-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Any plans for the new context API? #609
Comments
lets discuss :-) |
I'm far from an expert of HOCs, I think it's feasible, but I guess it will add 3 wrappers because of 1) the HOC, 2) the Context component, 3) the render prop I'm not sure if this is going to be a problem. |
In my mind, it would be something like:
|
Awesome @wuct . From my side I would like to add to getContext above an optional map function, so we could rename context variables. |
Looks good to me :) |
Hi all, you may be interested in this. I have just published a npm package -- https://github.com/SunHuawei/with-context. I think it is the easiest way to use the new context API. |
@SunHuawei the string key here might be a pain in type systems. |
@SunHuawei looks solid upon cursory glance. I wish that this was just how context worked in recompose |
@wuct , thanks for your kind reminder. I'm not not sure what is the type systems you mentioned, the type system like flow/typescript, or PropTypes? However, any suggestion for that? I must have something to learn, honestly, could you show me the path? |
Using string keys means you can't determine what props will be pass to the base component until runtime, so you can't type the HOC with Flow/TypeScript. To avoid this problem, you can use a function instead. You can compare how we type |
@wuct , thanks a lot. I think I have much things to learn. |
@wuct Looking at your proposal maybe these names would be most obvious? I don't feel like "with" is always the most intuitive naming convention. Just thinking out loud...
|
Just few cents. about @wuct proposal
Avoiding rerenders using current HOCs withPropsOnChange(['color'], ({ color }) => ({ newContext: { color } }) ),
withContext(({ newContext }) => newContext) One of ideas is to combine both above into one |
The main helper that I've been using all the time with new context is |
How about separating the logic of import { withConsumerProps } from 'recompose';
const { Consumer: I18NConsumer } = React.createContext({ i18n: 'en' });
const enhance = compose(
// Context (Function as Child Components)
withConsumerProps(ThemeConsumer, ({ theme }) => ({ theme })),
withConsumerProps(I18NConsumer, ({ i18n }) => ({ i18n })),
// Render props
withConsumerProps(Item, ({ value }) => ({ value }), 'render'),
); |
@evenchange4 What |
I agree with @wuct. Ideally we want to be able to continue using const SomeComponent = compose(
withRouter,
fromRenderProps(ThemeContext.Consumer),
)(SomeButton); |
Are there any news about this ? |
https://github.com/acdlite/recompose#a-note-from-the-author-acdlite-oct-25-2018 |
I think fromRenderProps should be usable for handling context. That said the lack of attention paid to the new context system is really disappointing. Especially given the fact that the new context API has been around for awhile + hooks have not even been released in a stable version yet + even after release hooks are severely crippled in regards to context usage until we fix facebook/react#14110. |
Just need time to implement it. A pull request is welcome. |
For those that found this thread and want something now, here's a pretty simple implementation using Hooks. It would obviously need a better provider HOC but I'm already slamming so many providers into my apps these days with nest(....) I don't particularly care. |
Is it dead? (( |
Yes, have a look at README |
Is there already some work done to support the upcoming context API?
It makes use of render props so I don't know how well will it fit with recompose, is this even going to be take in consideration?
The text was updated successfully, but these errors were encountered: