You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
588 B

// After
class ExampleComponent extends React.Component {
// highlight-range{1-3}
// Initialize state in constructor,
// Or with a property initializer.
state = {};
// highlight-range{1-20}
static getDerivedStateFromProps(
nextProps,
prevState
) {
if (
prevState.someMirroredValue !==
nextProps.someValue
) {
return {
derivedData: computeDerivedState(
nextProps
),
someMirroredValue:
nextProps.someValue,
};
}
// Return null to indicate no change to state.
return null;
}
}