let say I have state in redux
const initialState = {
age: 0,
title: undefined,
body: undefined,
author: undefined
}
I want to update it with the newState that I get from my backend and it has exactly the same key (age, title, body, author) so in order to make it immutable, I use spread operator
const updateState = (state, newState) => {
return {...state, ...newState}
}
The problem is that this function works well but what if the body is a object and has nested object in it. I want to make a function that I can reused. I dont want to update it manually key by key
I came across Immer and still cannot figure out how to make a function updateState (not update key by key manually). Could you please show me how to do it?