0

I am getting an error in the selectors of a react application when using toJS with the reselect library. I tried importing toJS as well as not importing it and I get the error no matter what.

nodeCreationWindow.get(...).toJS is not a function

import { createSelector } from 'reselect'
import { toJS } from 'immutable'

const selectNodeCreationWindow = () => (state) => state.get('nodeCreationWindow')

const selectNodes = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => {
    return nodeCreationWindow.get('nodes').toJS()
  }
)

const selectTags = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => nodeCreationWindow.get('tags').toJS()
)

const selectSuggestions = () => createSelector(
  selectNodeCreationWindow(),
  (nodeCreationWindow) => nodeCreationWindow.get('suggestions').toJS()
)


export {
  selectNodes,
  selectTags,
  selectSuggestions
}
Grzes Slania
  • 588
  • 1
  • 11
  • 28

1 Answers1

1

I think that value returned by nodeCreationWindow.get('nodes') is already a pure JS object so it doesn't have toJS method.

Besides, remove this line:

import { toJS } from 'immutable'

because toJS is not exported by Immutable module but attached to Immutable objects

Bartek Fryzowicz
  • 6,464
  • 18
  • 27