Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is initialState in a mixin merged with initialState in a component?

Simple question : if component A declares getInitialState and uses mixin M that also declares getInitialState, will both be merged in the "final" component A ?

Use case : I have several forms which share fields and associated state, and I want to avoid code duplication between them, so that each component declares only what's specific to it. I already used mixins in the recent past, but never with state.

like image 487
DjebbZ Avatar asked May 26 '14 14:05

DjebbZ


1 Answers

Yes, it's possible to merge the state from component A and the state declared in mixin M used by A if the states don't share keys. If they share keys, the Error "Invariant Violation: mergeObjectsWithNoDuplicateKeys()" will be thrown.

PS: using React.js 0.9.0.

like image 62
DjebbZ Avatar answered Oct 05 '22 23:10

DjebbZ