It uses the concept of containers .
Suppose you want to display the Login component inside your App . You will create a connected container.
Step 1 is to create a simple action:
const LOGIN_ATTEMPT = 'auth/LOGIN_ATTEMPT'; export const login = name => ({ type: LOGIN_ATTEMPT, payload: { name }, });
You are now using react-redux to associate this action with your presentation component. This will be passed to the component as prop .
import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { login } from 'actions/auth'; // your action import Login from 'components/auth/Login'; // your component to connect it to. // state refers to the "current state" of your store. const mapStateToProps = state => ({ currentUser: state.auth.user }); // dispatch refers to `store.dispatch` const mapDispatchToProps = dispatch => { // calling this is like calling `store.dispatch(login(...params))` login: bindActionCreators(login, dispatch); } export default connect(mapStateToProps, mapDispatchToProps)(Login);
This connect function will take these two functions as parameters. Now you can import this connected container and use it with functions that are βboundβ to it as properties.
An example is below.
export default class Login extends Component { static propTypes = {
Please note: you never had to refer to the store.
source share