Docs: What's the type of `type`?
RayPS opened this issue · comments
Hi, first for all thanks for making this fantastic state manager.
I want to make a centralized state selectors.
This example below I saw in the doc has bring me questions.
const MyComponent = ({ type }) => {
const data = useStoreState(MyStore, (s) => s[type], [type]);
// OR
const data = MyStore.useState((s) => s[type], [type]);
// do stuff with data
}
What is type
exactly? I don't have { type }
prop in my components, where do this come from?
What's the type of type
? It's looks like a String
to me as it's using for getting sub-states from states.
Then it looks like a dependency to me.
What is it?
Hi @RayPS ,
type
is a generic example. It means nothing specifically to Pullstate or to any exact project.
It is in a part of the documentation that is explaining that you can select state on your Store which is reliant on an incoming variable- type
in this case. It could be anything- such as id
, or userId
or whatever. The main point is that you can cause your state selectors to "reselect" the state again if an incoming variable changes. This is the same as something like useEffect
etc- where you need it to "re-evaluate" if a dependency changes.
If you read the section above the code, it explains it more. It could be made more obvious by letting you know type
is nothing specific to Pullstate- its simply for the sake of example.
Hope that helps.
You explained well, thanks for the help!