Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Context Transform #12234

Closed
sebmarkbage opened this issue Feb 15, 2018 · 8 comments
Closed

Context Transform #12234

sebmarkbage opened this issue Feb 15, 2018 · 8 comments

Comments

@sebmarkbage
Copy link
Collaborator

With the new context API it is really bulky to create a middle man that consumes one context value, transforms it and provides another one. You have to create many components and store an intermediate state to avoid rerendering the provider if the input is unchanged.

We could have a convenience API for this use case.

function transform(inputValue) {
  return [...inputValue, extraData];
}

<Context.Middleware transform={transform}>{children}</Context.Middleware>

cc @acdlite

@acdlite
Copy link
Collaborator

acdlite commented Feb 16, 2018

I like this but for the love of god let's not call it middleware, please :)

@gaearon
Copy link
Collaborator

gaearon commented Feb 16, 2018

Context.Map?

@acdlite
Copy link
Collaborator

acdlite commented Feb 16, 2018

Yeah I like Context.Map or Context.Transform

@sebmarkbage
Copy link
Collaborator Author

I like Context.Transform. Map is so overloaded. Is it a <map> tag, is it a Google Maps map, is it a hash new Map() object...?

@acdlite
Copy link
Collaborator

acdlite commented Feb 16, 2018

Alternatively, we could add a transform prop to Context.Consumer

@milesj
Copy link
Contributor

milesj commented Feb 16, 2018

Third-party vote for Context.Transform. Just by the name, it's pretty apparent what it does, and has some connotation to Node stream transforms.

@drcmda
Copy link

drcmda commented Feb 16, 2018

@sebmarkbage i think this is doable in user-land: https://codesandbox.io/s/mjv84k1kn9

Looking at the context api it seems very low level, curious if you really expect plain use that would warrant more add-ons. As it is, everything can be a bit verbose, transforms, creation, reading and sharing. But if it's kept relatively simple and focussed, doing one thing well, then that would be fine as user-land will build patterns around it.

@sebmarkbage
Copy link
Collaborator Author

This is sufficiently covered by #13139

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants