docs: Adds a note for each store that uses context #1938
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR simply adds a note to each of the stores stating that their respective store getter functions must be invoked at the top level of a component.
I also noticed that we weren't exposing the type for each of the stores, so I went ahead and added that with this PR.
Changes
ToastStore,DrawerStore, andModalStoreCopying over the original message from Discord here too:
I think this is another topic worth bringing up. Looking into this, the introduction of using contexts to store our
toastStore,modalStore, anddrawerStorehas 1 apparent limitation. In order to retrieve the stores with contexts, we have to call these functions at the top level of components.For instance, this is valid code:
So, in order to use the
toastStore(and the others), the store must first be retrieved at the top levels of components to be used.This means that we can't do something like this:
As we haven't seen many reports of this as part of v2, I figure the usage of calling the
getToastStoreoutside of the top level of a component is fairly uncommon. But for someone who is trying to refactor their code, a reasonable person could assume that they can takegetToastStoreoutside of a component into it's own module, like atoast.tsfile.If a user want's to create a module for reusable triggers, they'll have to do it like this:
Where they pass the
toastStoreto the reusable function. It's a tradeoff, but something that is probably worth documenting