Created
July 2, 2018 15:54
-
-
Save mbbertino/ab83744638e40f5ea969f0e6682e9266 to your computer and use it in GitHub Desktop.
This file contains 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
// 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