1.

How can we use connect from react redux?

Answer»

In order to use connect from React REDUX, we will have to follow a couple of steps to use our store in our container:

  • Firstly, we use the mapStateToProps(): This would map the state VARIABLES from our store to the props which we specify.
  • Secondly, we connect the above props to our container: The OBJECT returned by the mapStateToProps component is connected to the container.

A sample code for connect from react-redux is GIVEN below:

import React from 'react';import { connect } from 'react-redux'; class App extends React.Component { render() { return <div&GT;{this.props.containerData}</div>; } } function mapStateToProps(state) { return { containerData: state.appData }; } export default connect(mapStateToProps)(App);function mapStateToProps(state) { return { containerData: state.data };}export default connect(mapStateToProps)(App);


Discussion

No Comment Found