Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 29, 2019 19:27
Show Gist options
  • Save jsmanifest/8aab7fe72c4f3e5e93a9c3945a46269d to your computer and use it in GitHub Desktop.
Save jsmanifest/8aab7fe72c4f3e5e93a9c3945a46269d to your computer and use it in GitHub Desktop.
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