user2602079
user2602079

Reputation: 1403

Redux store as an immutable.js map

I'm getting this error when building my react native app:

The preloadedState argument passed to createStore has unexpected type of "Object". Expected argument to be an object with the following keys: "height", "width"

I think the redux store should be an immutable.js Map.

Here is my createStore code:

import { Map } from 'immutable'
import { createStore, combineReducers } from 'redux'
import { Provider } from 'react-redux'
import { Volcalc } from './components/volcalc/Volcalc'
import { width } from './components/width/width.reducer'
import { height } from './components/height/height.reducer'
import React from 'react'

const initialWidth = Map({ 'width1': 20, 'width2': 0, 'width3': 0 })
const initialHeight = Map({ 'height1': 6, 'height2': 0 })
const initialState = Map({height: initialHeight, width: initialWidth})
const reducer = combineReducers({ height, width })
const store = createStore(reducer, initialState)

If I change initialState to this, it works:

const initialState = {height: initialHeight, width: initialWidth}

but now the store is not an immuatble.js map. How do I make the redux store be an immutable.js map? (My reducers do work with an immutable.js map).

Upvotes: 1

Views: 859

Answers (1)

Tharaka Wijebandara
Tharaka Wijebandara

Reputation: 8065

When you are using combineReducers method comes with default redux package, your second argument to the createStore always should be a plain JavsScript object.

Since you need to use an immutable object for your initial state in createStore, you have to use special implementation of combineReducers method which comes with redux-immutable package.

You can read the documentation of 'redux-immutable' package to get a better understanding.

Upvotes: 2

Related Questions