Search code examples
javascriptreactjsreduxselectorimmutable.js

Import get method from immutable but cannot read in my selector


I used Immutable JS in my react project and I want to use get method in my selector file but it failed to recognize by my "getAllAppointments" and "getQuery" functions.

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

const getAllAppointments = state => state.get('allAppointments')

const getQuery = state => state.get('query')

export const getVisibleAppointments = createSelector(
    getAllAppointments,
    getQuery,
    (appointment, query) => {
        return (!query) ?
            appointment :
            appointment.filter(item => item.title.toLowerCase().includes(query))
    }
)


Solution

  • From Immutable.js docs https://immutable-js.github.io/immutable-js/docs/#/get get operator doesn't work in that way.

    Try using it:

    const getAllAppointments = state => get(state, 'allAppointments')
    
    const getQuery = state => get(state, 'query')