score:1

Accepted answer

I believe you need to use connect and mapStateToProps for this requirement. What we need to do is use connect function from react-redux, your component would look something like this -:

import { connect } from "react-redux";
import {Component} from "react";

class YourComponent extends Component {
    constructor(props){
        super(props);
        this.state = props.data;
    }
    // Your component code.....
}

export const mapStateToProps = state => ({
  data: state.data,
});

export default connect(mapStateToProps)(YourComponent);

score:2

Once you have hooked up your redux store into your react application, using the approach recommended by @Abhisar. Your component automatically watches your state for changes and re-renders whenever there is a change in your redux state.

Also, see the official React Redux Doc


Related Query

More Query from same tag