gajus / gajus/redux-immutable

Why can't I use Immutable.Record as initialState in rootReducer?

Open
#66 6 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
TypeScript
Stars
1.9k
Forks
84
PR merge metrics
No merged PRs in 30d

Description

As I can see in [https://medium.com/@fastphrase/practical-guide-to-using-immutablejs-with-redux-and-react-c5fd9c99c6b2](https://medium.com/@fastphrase/practical-guide-to-using-immutablejs-with-redux-and-react-c5fd9c99c6b2) It should be possible to use Record as `initialValue`, but using `combineReducers` I get an Error, if I use `Immutable.Record` instead of `Immutable.Map` in `redux` `createStore` . Please explain.

I use `redux-immutable`'s `combineReducers` and all my reducers now made with `Immutable.Record`.
But as it is in example in `redux-immutable` github examples, store should be created with `Immutable.Map` as initialState.

```
const initialState = Immutable.Map()
const store = createStore(rootReducer, initialState)
```

I tried to change it to
```
const initialState = Immutable.Record()
const store = createStore(rootReducer, initialState)
```

But I'm getting errors from Immutable lib. Is there some workaround? It could be very helpful, if someone point me in the right direction.

PS. "react-redux": "5.0.5"

The main reason for the issue is API.

Using `Record` as initialState allows to get data from state in `connect`ed components I can:
```
export default connect(
state => ({
someProp: state.reducer.value
})
)(SomeComponent)
```

With `Map` i can only get data:
```
export default connect(
state => ({
someProp: state.getIn(['reducer', 'value'])
})
)(SomeComponent)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.