从不可变导入get方法,但无法在选择器中读取

时间:2019-02-26 10:05:14

标签: javascript reactjs redux selector immutable.js

我在我的react项目中使用了Immutable JS,但我想在选择器文件中使用get方法,但是我的“ getAllAppointments”和“ getQuery”函数无法识别它。

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))
    }
)

1 个答案:

答案 0 :(得分:0)

从Immutable.js文档https://immutable-js.github.io/immutable-js/docs/#/get get运算符无法以这种方式工作。

尝试使用它:

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

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