How to properly use React-Redux typings
See original GitHub issueI can’t seem to find a single guide around properly using react-redux typings.
I am thinking I need something like this:
import type { MapStateToProps, MapDispatchToProps } from 'react-redux';
type TMapStateToFilter = MapStateToProps<DataExplorerState, { filters: FilterData[] }, {loading: boolean, filters: FilterData[]}>
const mapStateToFilterProps: TMapStateToFilter = (state) => ({ loading: state.loading, filters: state.filters });
const mapDispatchToFilterProps: MapDispatchToProps<Action, {}, *> = (dispatch) => ({
updateFilters(filters) {
dispatch({ type: "UPDATE_FILTERS", payload: filters })
},
updateData(data) {
dispatch({ type: "UPDATE_DATA", payload: data })
},
updateLoadState(loading) {
dispatch({ type: "LOAD", payload: loading })
}
});
export const FilterBoxConnect = connect(
mapStateToFilterProps,
mapDispatchToFilterProps
)(FilterBox)
But it seems wrong as MapStateToProps
and MapDispatchToProps
are not exported and I needed to edit the type definition.
There is a preferred way to doing this, right?
Issue Analytics
- State:
- Created 5 years ago
- Comments:27 (17 by maintainers)
Top Results From Across the Web
Usage with TypeScript - React Redux
In order to correctly dispatch thunks, you need to use the specific customized AppDispatch type from the store that includes the thunk ...
Read more >How to Use Redux in Your React TypeScript App
Prerequisites · Setting up the project · Create the types · Create the action types · Create the action creators · Create a...
Read more >React & Redux in TypeScript - Complete Guide - GitHub
The complete guide to static typing in "React & Redux" apps using TypeScript - GitHub - piotrwitek/react-redux-typescript-guide: The complete guide to ...
Read more >React Web App with TypeScript and Redux - Medium
React, Redux, and TypeScript a quick start guide, How to use Redux Dev Tools, How to use Redux Toolkit with React, Simple React...
Read more >Using React Redux with TypeScript -- newline - Fullstack.io
We will use create-react-app to generate a stock React app. We can generate a TypeScript-based app by specifying the template argument as below....
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 @villesau, that does help a bit! Had never heard of the placeholder
_
type, seems to be documented nowhere 😕Think i’ll recommend my team to stay on 0.84 a few more months until the dust settles a bit. Flow has definitely been the most painful thing for us to keep up to date in 2018:
Sorry, bit of a rant here, I know it’s an open source effort but I guess we’ve been spoiled too much by react and expect the same for all other fb-driven projects as well now…
react-redux libdefs have been rewritten since the issue so I assume it’s not longer an issue with more recent versions of Flow. I’m going to close this. Feel free to reopen if you encounter this with up-to-date Flow versions.