Closed pgarciacamou closed 6 years ago
mapContextToProps
context
UNSAFE_withContext
withContextAsProps
If [A,B,C] are Context APIs and [a,b,c] are the consumed context, then:
Before:
withContext(A,B,C)(Comp)
<Comp context={...a, ...b, ...c} />
Now:
withContextAsProps(A,B,C)(Comp)
<Comp {...a} {...b} {...c} />
withContext([A], mapContextToProps)(Comp)
<Comp {...mapContextToProps({...a}) />
This PR also included validations. I opted to remove that feature because the use of invariant, react-is, lodash.isfunction, and lodash.isstring were bloating the size of the library from 2KB to 20KB.
invariant
react-is
lodash.isfunction
lodash.isstring
Fixes #7
Checklist
Short description of what this PR does:
mapContextToProps
context
wrapper explained in #7. Renamed toUNSAFE_withContext
.withContextAsProps
and injects the context as separate props into the component.Code example
If [A,B,C] are Context APIs and [a,b,c] are the consumed context, then:
Before:
withContext(A,B,C)(Comp)
-><Comp context={...a, ...b, ...c} />
Now:
withContextAsProps(A,B,C)(Comp)
-><Comp {...a} {...b} {...c} />
withContext([A], mapContextToProps)(Comp)
-><Comp {...mapContextToProps({...a}) />
This PR also included validations. I opted to remove that feature because the use of
invariant
,react-is
,lodash.isfunction
, andlodash.isstring
were bloating the size of the library from 2KB to 20KB.