Khoa Võ Đức
Khoa Võ Đức

Reputation: 43

What happen with mapstatetoprops in redux?

this file index.js

import {Provider} from 'react-redux'
import {createStore} from 'redux'
import rootReducers from './rootReducers'
const store = createStore(rootReducers)
ReactDOM.render(
  <Provider store = {store}>
    <App />
  </Provider>,
  document.getElementById('root')
);

this id file rootreducers.js

const todos = [
    { id: 1, name: "Khoa" },
    { id: 2, name: "Khoai" },
    { id: 3, name: "Kha" }
  ];
  const TodoList = (state = todos, action) => {
    switch (action.type) {
      default:
        return state
    }
  };
  export default TodoList;

this is file list.js

import React, { Component } from "react";

import {connect } from "react-redux";

class List extends React.Component {
  render() {
    console.log(this.props.todoList);

  }
};
mapStateToProps = (state) => {
  return {
    todoList: state // err this code
  };
};
export default connect(mapStateToProps, null)(List);

i'm install react-redux and redux but when i write method mapstatetoprops it message : 'mapStateToProps' is not defined. help me.

Upvotes: 0

Views: 31

Answers (1)

Ishant Solanki
Ishant Solanki

Reputation: 207

mapStateToProps is simply an object. You need to initialize as a variable, preferably a const

const mapStateToProps = (state) => {
  return {
    todoList: state // err this code
  };
};

Upvotes: 1

Related Questions