-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: new hook useProvideContext #452
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 23b7541 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 |
✅ Deploy Preview for hauntedhooks ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
e285f9c
to
3906e83
Compare
"haunted": minor | ||
--- | ||
|
||
New hook: useProvideContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be documented in readme and on the docs site
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bennypowers I have added documentation for the hook.
Do I have to also update custom-elements.json (with the results of npm run analyze
)?
This hook enables you to provide values to one or multiple contexts from the same component. Instead of: ```html <app-state-provider .value=${appState}> <settings-provider .value=${settings}> <main-app></main-app> </settings-provider> </app-state-provider> ``` you can do: ```js useProvideContext(AppStateContext, appState, [appState]); useProvideContext(SettingsContext, settings, [settings]); ```
3906e83
to
4069d4f
Compare
@bennypowers this code duplicates a lot of the code from the Provider in makeContext. The Provider component could be rewritten as: Provider = component(({value}) => useProvideContext(Context, value), {useShadowDOM: false}) Do you think that would be a good idea? |
will these interop with |
I don't know. This PR is just re-implementing the existing haunted Context Provider as a hook. |
We need to at some point have a conversation on how to add features to Haunted without unnecessarily increasingly the bundle size. Like, this feature seems useful but a large number of projects will never need context. Does it make sense to make this kind of thing available via |
@matthewp isn't this already mitigated by the fact that you're publishing the package as an es6 library? I think most bundlers will tree-shake the context if it's not used at all. |
This hook enables you to provide values to one or multiple contexts from the same component.
Instead of nesting multiple Provider elements:
you can do all of it in the same component hook: