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 } }
Grund source share