M
M
mr jeery2018-02-19 06:39:46
React
mr jeery, 2018-02-19 06:39:46

How to remove/apply filter using immutable.js?

This is the initial_state

const INITIAL_STATE = Immutable.fromJS({
    cards: List([])
});

This is how I add the element, it works
const addCard = (state, action) => {
    console.log("addCardReducer", state.get('cards'))

    return state.update('cards', card => card.push(Map({
        id: Math.random().toString(36).substring(7) ,
        name: '',
    })))
}

How do I apply a filter
const deleteCard = (state, action) => {

  console.log("deleteCardReducer", state.get('cards'))

    return { cards: state.get('cards').filter (card => {
        return card.get('id') !== action.id
    }) }
}

I'm trying to do this, it gives me an error.
Please help, I'm just starting to learn immutable.js

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question