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.

Decide what to do with upcoming react api changes

See original GitHub issue

React just published a blog post about upcoming api changes due to the planned suspense api. The current lifecycle methods will be deprecated with react v17.

We should decide if we want to follow them or leave the lifecycle methods as is. Note that our rendering process is currently not asynchronous but synchronous so we don’t have the same problems as them.

List of API changes recently introduced by react:

  • getDerivedStateFromProps (#1094)
  • getSnapshotBeforeUpdate (#1112)
  • componentDidCatch (#819)
  • Fragments (#1080)
  • new Context API: currently no interest in bringing this into core (may change). preact-context is sort of a polyfill that can be used today
  • UNSAFE_componentWill* won’t be added to preact, simply continue using componentWill* hooks
  • ref-forwarding undecided, there hasn’t been any talk about this one yet
  • createRef (#1138)
  • createPortal

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:19
  • Comments:22 (10 by maintainers)

github_iconTop GitHub Comments

5reactions
marvinhagemeistercommented, May 19, 2018

We talked a bit on how we want to deal with the upcoming changes in yesterdays meeting. The general conclusion was to keep componentWill* hooks for now and add the new API getDerivedStateFromProps and getSnapshotBeforeUpdate. We won’t add the UNSAFE_componentWill* hooks like react did.

The reasons for changing the api are outlined in the react announcement post or in the original getDerivedStateFromProps and getSnapshotBeforeUpdate rfcs. Note that some arguments made there don’t apply to preact because our rendering is synchronous. To summarise:

getDerivedStateFromProps:

  • called when a component is created and when it receives new props.
  • static, to prevent mutation of props or state

Personally, I never thought that’d be an issue until I stumbled upon a component at work that mutated both state and props in componentWillReceiveProps. Moreover the author of that code was confused why componentWillReceiveProps is not called when the component is constructed.

getSnapshotBeforeUpdate:

  • called right before DOM mutations are applied
  • defined as static in the initial RFC but later changed back to a normal method
  • doesn’t have context argument like componentWillUpdate.

At this point I’m not sure if we need this for preact. Perhaps an alias is enough?

4reactions
andrewigginscommented, May 8, 2018

Opened PR #1094 for getDerivedStateFromProps

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 New API's In React 18 Every Developer Should Know
All you have to do is run npm install and install the latest versions of React and React DOM, and then there's one...
Read more >
Everything You Need to Know about React Context in 2022 ...
This excerpt explores using React Context.Read it if you're a React developer or want to learn more about React.
Read more >
Context
Changes are determined by comparing the new and old values using the same algorithm as Object.is . The way changes are determined can...
Read more >
React 18: What You Need to Know and What's Changing
Due to the fact that React 18 introduces a new root API, you'll need to make one important change to take advantage of...
Read more >
React 18 - What's New, What Changed & Upgrade Guide
React 18 was released and since it's a new major version, the big questions is: What changed ?Indeed, React 18 lays a solid...
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