-
Notifications
You must be signed in to change notification settings - Fork 133
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
Add ConsumeContext
#756
base: main
Are you sure you want to change the base?
Add ConsumeContext
#756
Conversation
🦋 Changeset detectedLatest commit: e71e4ad The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
this is a cool idea, but I don't like how you need a bound function (without parameters) to use it. When the default solid api for using the context is <Provider>
{untrack(() => {
const value = useContext(Ctx)
return <>{value}</>
})}
</Provider> |
If you mean the <ConsumeContext context={counterContext}>
{(ctx) => <>...</>}
</ConsumeContext>
// or
<ConsumeContext useFn={useCounter}>
{(ctx) => <>...</>}
</ConsumeContext> And for the easy alternative: |
Implemented the aforementioned ideas and added tests + docs |
what about <ConsumeContext use={useMyContext}>
<ConsumeContext use={() => useContext(MyContext)}>
<ConsumeContext use={MyContext}> by simply checking the Also it may be useful to mention in the docs that the prop will not be reactive. |
Oh, I totally forgot about this option, I will implement it later that day, thanks! |
Add a function to directly consume contexts within JSX. Inspired by React's
Context.Consumer
component, but nicely integrated with this primitive'screateContextProvider
.Tests have been added and source code + README.md is documented