Remove usage of unsafe lifecycle hooks (React 16.3)
See original GitHub issueBug, Feature, or Question?
Feature?
Current Behavior
Using Formik with React 16.3 with the <React.StrictMode></React.StrictMode>
component will trigger some warnings.
Desired Behavior
Different lifecycle hooks should be used.
Suggested Solutions
The warning message states:
Warning: Unsafe lifecycle methods were found within a strict-mode tree:
componentWillMount: Please update the following components to use componentDidMount instead: Field, Formik
componentWillReceiveProps: Please update the following components to use static getDerivedStateFromProps instead: Formik
The React team also made react-lifecycles-compat
which should allow for backwards compatibility when using the new lifecycle hooks.
Additional Information
More details are in the recent React blog post.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
React 16.3 Lifecycle Methods - Medium
The reason for the removal from use is the incorrect use of these methods in asynchronous applications. Dan's Twitter share featured a new...
Read more >Migrating from Unsafe React Lifecycle Hooks - YouTube
In this video I take an example React app and migrate the UNSAFE_ lifecycle hooks to use safer alternatives NOTE: You...
Read more >Using React's useEffect Hook with lifecycle methods
Learn about lifecycle methods in React and how we can use the useEffect Hook to use lifecycle methods in functional components.
Read more >Understanding React v16.4+ New Component Lifecycle ...
In React 16.3 few lifecycle methods have been deprecated. For now, these methods are prefixed with UNSAFE_ and will be fully removed in...
Read more >Strict Mode - React
As explained in this blog post, certain legacy lifecycle methods are unsafe for use in async React applications. However, if your application uses...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
There is a large rewrite required for 16.3. But the great news is that it will make Formik MUCH smaller, simplify tooling (microbundle), and no longer have prop-types as a peer dep.
@jaredpalmer is the large rewrite you are talking about here PR #423 ? We are happily using formik in a couple of projects, and would like to put a plan to get them moved to 16.3, but we want that to be coordinated with the new release of formik.
Where should we “track progress”, on that PR, or elsewhere? Let us know if there is any help needed once you have an RC, etc.