useSelector seems to have no type awareness
See original GitHub issueWhen making my own selector with typing
const practitionerAvailability = (state): availabilities => state.practitioner.availability.availabilities;
the returned type from useSelector is still type any when i do something like.
const a = useSelector(practitionerAvailability)
.
I made a little example in typescript which solves this
function useTypedSelector<T>(selector: (any)=>T): T {
return useSelector(selector)
}
Is there any way you guys could include the behaviour baked into the useSelector function. Thanks 😃
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
React-Redux useSelector typescript type for state
It is set by default as unknown so I get an error when I try to return state.SLICE_NAME ( Error: Object is of...
Read more >Redux Gotchas — useSelector - Level Up Coding
The selector function — stateSelector — is called whenever there is a state change to the subscribed property. State property — counter —...
Read more >Hooks - React Redux
When an action is dispatched, useSelector() will do a reference comparison of the previous selector result value and the current result value.
Read more >useSelector vs connect (react-redux) - Sam Dawson
React-redux hooks like and the can have the same outcomes. The main difference between them is their ability to nudge (guide) the way...
Read more >`state` in `useSelector` is undefined. How do I get around this?
However I'm not a React guy so I googled it, and it seems that you can tell useSelector a type, as user signsAndWonders...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks I was being silly didn’t install @types/react-redux as a dependency. Thanks for pointing me int he right direction
If you’re using TypeScript, we don’t maintain the types here. Those are on the DefinitelyTyped repo, so check with them for their support resources.