Skip to content

Conversation

Gokul-Gireesh
Copy link

This RFC proposes allowing React Context to accept non-children props as the provided value.

  • Keeps value for backward compatibility.
  • If no value is passed, all non-children props become the context value.
  • Excludes children from injection.
  • Simplifies context usage and makes it consistent with normal prop-passing in React.

Example:

<MyContext foo={foo} bar={bar}>
  <App />
</MyContext>

Consumer:

const { foo, bar } = useContext(MyContext);

First draft of feature request
Copy link

meta-cla bot commented Aug 30, 2025

Hi @Gokul-Gireesh!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@meta-cla meta-cla bot added the CLA Signed label Aug 30, 2025
Copy link

meta-cla bot commented Aug 30, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@josephsavona
Copy link
Member

josephsavona commented Aug 30, 2025

Thanks for posting. I don’t think we’re likely to proceed with this change: it’s confusing. In the existing API there’s a clear, 1:1 match between the value you pass to a context provider and the value you get back out w useContext(). The proposal has a number of issues:

  • implicit object creation
  • unclear what should happen if you pass both a value and other props
  • Hard to type in type systems

More fundamentally, it isn’t clear this is solving a real problem. We’re always open to exploring api changes, but in this case I don’t think we will proceed given the clear problems and lack of a strong motivation.

@Gokul-Gireesh
Copy link
Author

Thanks for the detailed feedback. I realize I may not have fully updated the PR comment when submitting — the Value Handling Rules in my commit already clarify how value is handled alongside other props.

I understand the concerns about implicit object creation, TypeScript typing, and whether this really solves a problem, and I see how that could add complexity.

Some of the points may reflect my earlier misunderstandings, so I appreciate the clarification and the focus on keeping the API predictable and backward-compatible.

@vezaynk
Copy link

vezaynk commented Sep 10, 2025

I think there's very little value in something that's trivially easy to implement by yourself.

const Context2 = ({ children, ...value }) => <React.Context value={value} children={children} />

@fuunnx
Copy link

fuunnx commented Sep 11, 2025

Yes but be carefull about performances here : you're recreating a new value object during each render. You may want to memoize it

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

Successfully merging this pull request may close these issues.

4 participants