Warning: componentWillReceiveProps has been renamed

Asked

Viewed 2,407 times

1

I have updated my React project from version 0.57.8 to the latest version and am receiving the following warning message:

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

I entered this link that appears Update on Async Rendering

I executed the recommended command in the tutorial:

cd your_project
npx react-codemod rename-unsafe-lifecycles

In the tutorial according to what I read, it seems that this command is to update the functions componentWillMount, componentWillUpdate, etc. But I still get the same warning message.

Can someone help me fix this?

  • The methods componentWillMount were renamed to componentDidMount?

  • In my case, the problem was happen because I’m trying to load a qr code Inside the Storybook. So, I created a Boolean state to identify when the scenario is a SB and apply a fake qr code (a generated image) and when it’s in Production, the real qr code will be called. Works Great for me. *** In my case, the problem happened because I’m trying to load a qr code into Storybook. Then, I created a Boolean state to identify when the scenario is a SB and apply a false qr code (a generated image) and when it is in production, the actual qr code will be called. Works great for

1 answer

4


According to the documentation React some life cycle methods of a React component will be discontinued, they recommend using the npm codemod to rename this method.

Footsteps:

  • npm i -g react-codemod
  • cd seuProjeto
  • npx react-codemod rename-unsafe-lifecycles

Browser other questions tagged

You are not signed in. Login or sign up in order to post.