Created
June 29, 2019 19:27
-
-
Save jsmanifest/8aab7fe72c4f3e5e93a9c3945a46269d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
class App extends React.Component { | |
constructor(props) { | |
super(props) | |
// Initialize the state on mount | |
this.state = { | |
items: props.items, | |
} | |
} | |
// Keep the state in sync with props in further updates | |
componentDidUpdate = (prevProps) => { | |
const items = [] | |
// after calculations comparing prevProps with this.props | |
if (...) { | |
this.setState({ items }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment