Re:React v16.6.0: lazy, memo and contextType
by danabramov on Tuesday October 23, 2018 @08:45PM
(#18288774)
This has been suggested in the RFC discussion (https://github.com/reactjs/rfcs/pull/65).
We intentionally didn't do it for several reasons:
* It adds extra object allocations on every render which adds up when your project grows
* It's harder to express in a type system (e.g. Flow or TypeScript)
You can use the low-level Consumer API to read multiple contexts but in this particular shortcut we're not going to support it.
Re:React v16.6.0: lazy, memo and contextType
by pcmaffey on Tuesday October 23, 2018 @09:04PM
(#18288852)
The other angle to solving this problem would be adding lifecycle methods to React.Context (instead of using render props), which could eliminate the need for multiple contexts. Making Consumer contexts more efficient & composable.
Re:React v16.6.0: lazy, memo and contextType
by danabramov on Tuesday October 23, 2018 @09:10PM
(#18288883)
We've thought about a spectrum of solutions and plan to present more proposals soon.
Re:React v16.6.0: lazy, memo and contextType
by wereHamster on Tuesday October 23, 2018 @11:55PM
(#18289597)
> It's harder to express in a type system (e.g. Flow or TypeScript)
I don't know about flow, but TypeScript is pretty flexible there. With mapped types you should be express anything you need.
In the example above, the context values would be available in this.form and this.app