question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove usage of unsafe lifecycle hooks (React 16.3)

See original GitHub issue

Bug, 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

10reactions
jaredpalmercommented, Apr 3, 2018

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.

2reactions
mikelaxcommented, Apr 5, 2018

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found