For now, when we wrap component with withStore and wrapped component uses update state function inside componentDidMount method or constructor - the state wont be updated properly.
But componentDidMount method or constructor of Component is called earlier than method componentDidMount of StoryState wrapper, because StoryState is parent for Component.
Maybe the solution will be to move store.subscribe(this.handleStateChange); to constructor of StoryState class?
For now, when we wrap component with
withStore
and wrapped component uses update state function insidecomponentDidMount
method orconstructor
- the state wont be updated properly.The demo can be found here:
http://kevich.github.io/issueDemos/dump247-storybook-state-update-issue-demo/storybook-static/?path=/story/storetest--test-with-did-mount
And code for demo component here:
https://github.com/kevich/kevich.github.io/blob/master/issueDemos/dump247-storybook-state-update-issue-demo/src/StoreTest.jsx
As of the reason of this behaviour is that
subscribe
function ofStore
in plugin called atcomponentDidMount
ofStoryState
wrapper (https://github.com/dump247/storybook-state/blob/master/src/index.js#L63).But
componentDidMount
method orconstructor
of Component is called earlier than methodcomponentDidMount
ofStoryState
wrapper, becauseStoryState
is parent forComponent
.Maybe the solution will be to move
store.subscribe(this.handleStateChange);
toconstructor
ofStoryState
class?