0

I'm working with redux and I have some issues on how to insert an object into an element of the state in an immutable manner. I have this type of state

   const Initial_State={
    filmList:[],
    title:'',
    description:'',
}
export default (state = Initial_State, action) => {
    const {PUSH,POP,CLEAR,SELECT}=ListKeys
    switch(action){
        case PUSH://need code to insert an object into filmlist
mario
  • 81
  • 5
  • You create a new array, e.g. `[...filmList, newEntry]`. See the answers [here](https://stackoverflow.com/questions/40911194/how-do-i-add-an-element-to-array-in-reducer-of-react-native-redux) for Redux-specific details. – T.J. Crowder Mar 20 '21 at 10:17
  • Please [search](/search?q=redux+add+to+array) before posting. More about searching [here](/help/searching). – T.J. Crowder Mar 20 '21 at 10:19
  • Also, please follow the official tutorials. You are writing a very outdated style of redux here. Modern redux, applied correctly (createSlice), does the immutability thing for you so you can just push into your array "mutably" when using it. – phry Mar 20 '21 at 11:36
  • forgot the link: https://redux.js.org/tutorials/index – phry Mar 20 '21 at 11:53
  • ty very much guys – mario Mar 20 '21 at 14:27

0 Answers0