Closed istarkov closed 6 years ago
The possible issues with current reset implementation is that if object Shape will be changed in initial
,
setState inside reset will merge new Shape with previous instead reset.
To avoid we need to make instead of this
class State extends Component {
state = {
...this.props.initial,
}
this
class State extends Component {
state = {
value: { ...this.props.initial },
}
It's fun but it was the first PR I made to react-redux ;-) moving state into value
Fixed in above setState implementation
BTW for my own case, I don't need that reset for every helper, and if we add Prop types to setState at State helper updater, I can reset State without resetState
method, just using
setState((_, {initial}) => initial)
So feel free to close the PR, as it so-so needed ;-) and for my case (having that I have stable object shapes) result can be achieved just making few flow type changes
Close in favor of #151
PS: TODO: Pick flow eslint from this PR and create new
Ref #110
see comment why
I've added in first commit eslint flow plugin as otherwise it's hard to edit
flow
file in editors like vscode (flow file is one big eslint error)cc @TrySound please check and i'll proceed with other Components