In React apps, state should be immutable. For every state change in our component, we should create a new state object. Consider the following state object.
const [complexState, setComplexState] = useState({
data: [
{
id: 1,
message: "Hello",
read: false
},
{
id: 2,
message: "World",
read: false
}
]
});
State object has a data property. This is an array of objects.…