I am still getting my head around functional programming and how to return a non mutated object from a reducer.
I am trying to replace the contents of an old object in a reducer, without mutating the old state.
so if the old state was
{
Actors:"Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl"
Awards:"Won 1 Oscar. Another 9 wins & 22 nominations."
Country:"USA, UK"
Director:"Tim Burton"
}
and the new state is
{
Actors:"George Clooney"
Awards:"Won 9 Oscars."
Country:"USA"
Director:"Quentin Tarantino"
}
My reducer looks like this
function reducer(state = {}, action){
switch(action.type) {
case 'GET_MOVIE':
return //new Array here that has not been mutatated
default:
return state;
}
}
My payload looks like this
{
Actors:"Michael Keaton, Jack Nicholson, Kim Basinger, Robert Wuhl"
Awards:"Won 1 Oscar. Another 9 wins & 22 nominations."
Country:"USA, UK"
Director:"Tim Burton"
}
action.payloadlooks like?arrayhere?