MapStateToProps should return an object. Instead, received a card {}?

Hello, I am using Immuteble Map for state, and when I try maspStateToProps, I have this error.

Non-invariant violation: mapStateToProps should return an object. Instead, a map {} was received.

Here is my code:

component:

  const mapStateToProps = (state) => { return state } class LoanCalculator extends React.Component{ componentWillMount(){ this.dispatch(loadConstraints()); } render(){ return ( <div> <h1> Loan Calculator </h1> <SlidersBox {...this.props}/> </div> ) } } LoanCalculator = connect( mapStateToProps )(LoanCalculator) export default LoanCalculator 

REDUCER

  import { Map } from 'immutable' import {LOAD_CONSTRAINTS, SET_AMOUNT_VALUE, SET_TERM_VALUE} from "../actions/actions"; const initialState = new Map(); export default function calculator(state = initialState, action){ switch (action.type){ case LOAD_CONSTRAINTS: return state.set("constraints", action.constraints) case SET_AMOUNT_VALUE: return state.set("selectedAmount", action.amount) case SET_TERM_VALUE: return state.set("selectedTerm", action.term) default: return state } } 
+5
source share
1 answer

This github issue covers this issue: https://github.com/reactjs/react-redux/issues/60 .

You can manually extract the desired values ​​from your Map in your mapStateToProps function:

 const mapStateToProps = (state) => { return { constraints: state.get('constraints'), selectedAmount: state.get('selectedAmount'), selectedTerm: state.get('selectedTerm'), }; } 
+11
source

Source: https://habr.com/ru/post/1244654/


All Articles