Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings about lifecycle methods #3741

Closed
TdyP opened this issue Aug 8, 2019 · 18 comments · Fixed by #3747
Closed

Warnings about lifecycle methods #3741

TdyP opened this issue Aug 8, 2019 · 18 comments · Fixed by #3747
Labels

Comments

@TdyP
Copy link

TdyP commented Aug 8, 2019

Bug Report

Steps

Use Dropdown with semantic-ui-react@0.87.3 and react@16.9.0-rc.0
Open your console to see the warnings

Expected Result

No warnings should appear

Actual Result

      Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

      * Move code with side effects to componentDidMount, and set initial state in the constructor.
      * Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run `npx react-codemod rename-unsafe-lifecycles` in your project source folder.

      Please update the following components: Dropdown

Version

0.87.3

Testcase

https://codesandbox.io/s/semantic-ui-react-y6s9z?fontsize=14

@welcome
Copy link

welcome bot commented Aug 8, 2019

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you've completed all the fields in the issue template so we can best help.

We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

@evanstern
Copy link

I can confirm this as well. I see it for more than just Dropdown. It should be seen for any component that uses the newly deprecated lifecycle methods.

I'm sure most of us have seen it but here are the release notes from React that outline the change that causes this issue:

https://reactjs.org/blog/2019/08/08/react-v16.9.0.html#renaming-unsafe-lifecycle-methods

@mcrawshaw
Copy link
Contributor

Suggest running the codemod to rename the lifecycle hooks.
npx react-codemod rename-unsafe-lifecycles

This will stop the warning messages.

@layershifter
Copy link
Member

Folks, thank you for mentioning the issue 👍
We will include these changes to upcoming release during next week, feel free to open PR 🚀

@mayhs007
Copy link

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

  • Move data fetching code or side effects to componentDidUpdate.
  • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
  • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: Dropdown, Menu


Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.

  • Move code with side effects to componentDidMount, and set initial state in the constructor.
  • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

Please update the following components: Dropdown

@charliematters
Copy link
Contributor

Is this different to #2732?

jmyrland pushed a commit to jmyrland/Semantic-UI-React that referenced this issue Aug 15, 2019
Executed via `npx react-codemod rename-unsafe-lifecycles --parser babel`
Disabled lint issues for updated lines.

Closes Semantic-Org#3741
Related to Semantic-Org#2732
@layershifter
Copy link
Member

@charliematters yep, in this issue we should fix warnings related to these methods via UNSAFE_ prefixing. While in #2732 we should completely remove all UNSAFE_ things.

layershifter pushed a commit that referenced this issue Aug 16, 2019
* chore(mixed): renamed unsafe lifecycle methods

Executed via `npx react-codemod rename-unsafe-lifecycles --parser babel`
Disabled lint issues for updated lines.

Closes #3741
Related to #2732

* bump react to ensure that CI will pass

* disable broken UTs
@layershifter
Copy link
Member

PR with fixes was merged, the release with these changes will be shipped during next week 🚀

@rinkisingh8181
Copy link

Hey @layershifter
Is there any updates on this?

@layershifter
Copy link
Member

It was released in 0.88.0 few hours ago.

@buithithuyquynh1993
Copy link

buithithuyquynh1993 commented Sep 16, 2019

Hey @layershifter
I just use react-codemod rename-unsafe-lifecycles to rename the lifecycle hooks. But I am still receive a warning message:
Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-async-component-lifecycle-hooks for details.
When I use: control + F with key: componentWillReceiveProps, I don't find any code have the hook.
Please help me

@layershifter
Copy link
Member

Have you upgraded to the latest? And why are you thinking that it's related to SUIR?

@buithithuyquynh1993
Copy link

buithithuyquynh1993 commented Sep 16, 2019

Have you upgraded to the latest? And why are you thinking that it's related to SUIR?

I installed "react-codemod": "^5.0.5". I don't know why application receive the warning: "componentWillReceiveProps has been renamed, and is not recommended for use" when I don't use the hook in source code
This is my warning:
image
This is my source file:

import * as React from "react";
import Router from "next/router";
import { ModalConfig, connectModal, InjectedProps, hide } from "redux-modal";
import { connect } from "react-redux";
import { Dispatch } from "redux";
import { ButtonGradient } from "@src/components/BaseButton";

interface ModalAggregateSuccessCardProps extends InjectedProps {
  gobackLink?: string;
  closeModal(): void;
}

class ModalAggregateSuccessCard extends React.Component<ModalAggregateSuccessCardProps> {
  constructor(props: ModalAggregateSuccessCardProps) {
    super(props);

    this.handleOnclick = this.handleOnclick.bind(this);
  }

  handleOnclick() {
    const { gobackLink = '' } = this.props;
    this.props.closeModal();
    Router.push(gobackLink);
  }
  
  render() {
    
    return (
      <div className={`modal kpfm-modal modal-household-term modal-advice modal-success 
         abc
      </div>
    );
  }
}

const modalConfig: ModalConfig = {
  name: 'AGGREGATE_SUCCESS_CARD_MODAL'
}

const mapDispatchToProps = (dispatch: Dispatch) => ({
  closeModal: () => dispatch(hide('AGGREGATE_SUCCESS_CARD_MODAL')),
})

export default connectModal(
  modalConfig
)(connect(
  null, 
  mapDispatchToProps
)(ModalAggregateSuccessCard))

@mcrawshaw
Copy link
Contributor

The ConnectModal is the component that hasn't upgraded. yesmeck/redux-modal#95

@buithithuyquynh1993
Copy link

buithithuyquynh1993 commented Sep 16, 2019

The ConnectModal is the component that hasn't upgraded. yesmeck/redux-modal#95

Yes, I see. I just check latest version of redux-modal ^3.0.2: https://github.com/yesmeck/redux-modal/commits/master. They haven't updated "componentWillReceiveProps" hook yet. Hope we will have the version update the warning soon.

@kapil-soni-nwea
Copy link

Hi Guys,
I removed all the deprecated lifecycle from my code even though I am getting these warnings.

Can someone help me that how would I suppress these warnings?
Below is the screenshot of the warnings-
image

Thanks in advance :)

@fracmak
Copy link
Member

fracmak commented Jan 3, 2020

Each of the warnings lists out the components that are in violation, immediately jumping out at me are react-router, and react-redux. Some are harder to recognize but I'd focus on those two first

@ghost
Copy link

ghost commented May 4, 2020

import { Header, Divider, Select } from 'semantic-ui-react';

These warnings still appear for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants