Add a type definition that accepts ThunkAction provided redux-thunk to useDispatch
See original GitHub issueWhat is the new or updated feature that you are suggesting?
From react-redux v8, it provides own type definitions. Along with that, a difference arose from the type definitions that were provided by volunteers in TypesDefinitions.
What I am having trouble with is the type definition of useDispatch
.
The current react-redux type definition only allows pure actions to be passed to dispatch.
Why should this feature be included?
It is helpful to maintain an ecosystem with third-party libraries surrounding react-redux.
What docs changes are needed to explain this?
Maybe nothing.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Usage With TypeScript
A thunk function receives dispatch and getState as its parameters. Redux Thunk has a built in ThunkAction type which we can use to...
Read more >typescript - type-safe useDispatch with redux-thunk
It allows to dispatch a ThunkAction , which basically is the inner function of requestUserName . For example, you can type it like...
Read more >Example with Typescript, react-redux, and redux-thunk #213
I am getting this typescript error: Property 'then' does not exist on type 'ThunkAction<Promise<boolean>, IinitialState, undefined, any>'. FYI I ...
Read more >How to Use Thunks with Redux Toolkit and TypeScript
All the work is done in the redux-thunk middleware. It extends the store's abilities and lets you write async logic that interacts with...
Read more >Using TypeScript with Redux Toolkit
Simplify state management in React using Redux Toolkit and TypeScript to easily scale and adapt large projects.
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 Free
Top 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
Hiya. The issue here is that there’s no guarantee that the actual Redux store being used was configured to have the thunk middleware. So, if we just automatically have the types include support for thunks, we’re actually lying to our users about how the runtime behavior will work.
This is also how the types in DefinitelyTyped have always behaved, as far as I know.
Because of that, we specifically teach and show how to infer the final real type from
store.dispatch
, and create a “pre-typed” hook that captures that for use within the rest of the app:https://react-redux.js.org/using-react-redux/usage-with-typescript#standard-redux-toolkit-project-setup-with-typescript
Found the difference I guess. My thunk was named
UploadFilesStep
while my slice wasuploadFilesStep
. Seems it matters somehow. thx for the help