[Warning] componentWillReceiveProps has been renamed, and is not recommended for use.

yunjeong·2021년 7월 29일
0

React-Native 컴포넌트 중 'react-native-action-button' 플로팅 버튼(https://github.com/mastermoo/react-native-action-button)을 사용할 경우,

Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://reactjs.org/link/unsafe-component-lifecycles for details.

이러한 warning이 발생한다.

이는 ActionButton 코드 상에 사용되었던 componentWillReceivePropsUNSAFE_componentWillReceiveProps으로 이름이 변경되었으며, 17버전부터는 사용이 중단되고 새로운 이름만 작동하도록 변경되었기 때문이다.



워닝이 났을 경우 터미널에 위 같은 안내문구가 나오는데, 안내된 대로

npx react-codemod rename-unsafe-lifecycles

를 실행하면 해결될... 줄 알았으나, 나같은 경우 죄다 skipped만 됐다.


docs를 찾아본 결과,

이제는 componentWillReceiveProps 자체를 사용해선 안된다고 하여,

문제가 된 컴포넌트를 제시된 방법으로 'componentDidUpdate'로 바꿔주니 워닝이 사라졌다.

내가 사용했던 react-native-action-button의 경우

ActionButtons.js 에서 42번째 라인의

componentWillReceiveProps => componentDidUpdate 로 변경하면 해결된다.

출처 :

https://ko.reactjs.org/docs/react-component.html#updating

https://github.com/mastermoo/react-native-action-button/issues/365#issuecomment-797476260

profile
거침없이 한 달음에!

0개의 댓글