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.

[npm:create-react-class] No way to implement getDerivedStateFromProps

See original GitHub issue

There seems to be no way to implement class methods such as getDerivedStateFromProps and a few others.

Am I overlooking something?

There is no mention of it here either: https://reactjs.org/docs/react-without-es6.html

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
gaearoncommented, Sep 30, 2018

This should work, no?

var Button = createReactClass({
  statics: {
    getDerivedStateFromProps() {
      // ...
  },
  render() {
    // ...
  }
});

Note getDerivedStateFromProps is generally meant to be last resort and not recommended except a few edge cases.

What other methods did you have a problem with?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React.Component
This page contains a detailed API reference for the React component class definition. It assumes you're familiar with fundamental React concepts, ...
Read more >
React.js static getDerivedStateFromProps() - GeeksforGeeks
React.js static getDerivedStateFromProps() · Step 1: Create a React application using the following command: npx create-react-app foldername.
Read more >
create-react-class - npm
Start using create-react-class in your project by running `npm i ... There are 1713 other projects in the npm registry using create-react-class.
Read more >
How to use lifecycle method getDerivedStateFromProps as ...
Below is an example I found online: State derived from props/state. Before class ExampleComponent extends React.Component { state = { ...
Read more >
Class Components - React TypeScript Cheatsheets
Derived State can be implemented using hooks which can also help set up memoization. Here are a few ways in which you can...
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