in React JS by
Q:

How to use connect() from React Redux?

1 Answer

0 votes
by

You need to follow two steps to use your store in your container:

  1. Use mapStateToProps(): It maps the state variables from your store to the props that you specify.

  2. Connect the above props to your container: The object returned by the mapStateToProps function is connected to the container. You can import connect() from react-redux.

    import React from 'react'
    import { connect } from 'react-redux'

    class App extends React.Component {
      render() {
        return <div>{this.props.containerData}</div>
      }
    }

    function mapStateToProps(state) {
      return { containerData: state.data }
    }

    export default connect(mapStateToProps)(App)

Click here to read more about React JS
Click here to read more about Insurance

Related questions

0 votes
asked Mar 3, 2020 in React JS by miceperry
0 votes
asked Dec 8, 2020 in React JS by SakshiSharma
0 votes
0 votes
asked Mar 1, 2020 in React JS by RShastri
0 votes
asked Nov 26, 2019 in React JS by AdilsonLima
0 votes
0 votes
asked Feb 23 in React JS by SakshiSharma
...