Skip to content

Instantly share code, notes, and snippets.

@mbbertino
Created July 2, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbbertino/ab83744638e40f5ea969f0e6682e9266 to your computer and use it in GitHub Desktop.
Save mbbertino/ab83744638e40f5ea969f0e6682e9266 to your computer and use it in GitHub Desktop.
// Current structure
constructor(props) {
super(props)
this.state = {
isValidating: false,
processing: false,
// ... other state setting from custom functions
// ... other state setting from props
}
}
// Second pass
static defaultState = {
isValidating: false,
processing: false,
}
constructor(props) {
super(props)
this.state = {
...CheckoutContainer.defaultState
// ...
}
}
// third pass
// This solves the main issue I had with the first pass however in a more standard way. There shouldn't be any performance issues.
// That said is it weird to have a function that just returns static values?
constructor(props) {
super(props)
this.state = {
...this.defaultState()
// ...
}
}
defaultState = () => ({
isValidating: false,
processing: false,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment