question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to properly use React-Redux typings

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:27 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
chapati23commented, Jan 1, 2019

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:

  • many breaking changes
  • no semver
  • no explanations for breaking changes (deprecated existential type is still in the docs, placeholder type isn’t, etc…)
  • flow-typed packages have a hard time to keep up with the latest flow version as well…

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…

0reactions
villesaucommented, Mar 2, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found