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.
this should be documented in readme and on the docs site
There was a problem hiding this comment.
@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: