delorean
delorean copied to clipboard
componentWillUpdate prevState
Due to react not deep cloning objects (https://github.com/facebook/react/issues/2914) and the way that Delorean passes entire stores into state this makes the prevState parameter of componentWillUpdate useless. The prevState is always the current state.
thoughts?
my thought is that this is an excellent point. For some reason I have not run into this yet. I think the solution is related to this issue. We need to create schema keys on a sub object and set those on state directly rather than dropping them all under state.stores.
Agreed. For those that come across this I actually overcame the limitation for my situation by reading the state in the parent component and passing the prop in individually.
Been giving this a lot of thought, and the main issue is that if you apply store state properties directly to component state, you risk name conflicts. Delorean's default behavior is to give every store's state to every component. IMO, using watchStores is a no-brainer, and it will certainly lower the risk of state name conflicts, but it still exists.
Pros for this change
- full compatibility with React's lifecycle methods
- no more of this obnoxiousness:
var myStateProp = this.state.stores.myStore. myStateProp;
Cons
- major breaking change (upgrade path would mean visiting every
rendermethod in an app) statename conflicts across stores (this could potentially be mitigated with aconsole.warnwhen it occurs)