I am wondering how do I push an object to an array that is located inside to another array, using useState. below is my code:
import React, {useState} from 'react';
const Context = React.createContext();
export const Provider = ({children}) =>{
const [categories, setCategory] = useState([
{ title: 'Personal' , id: Math.floor(Math.random()* 99999), notes: [
{ noteTitle: 'stam',
noteContent: 'stamstamstam',
id: Math.floor(Math.random()* 99999)
},
{ noteTitle: 'stam2',
noteContent: 'stamstamstam232323',
id: Math.floor(Math.random()* 99999)
}
]},
{ title: 'Work' , id: Math.floor(Math.random()* 99999), notes: []},
{ title: 'Shopping' , id: Math.floor(Math.random()* 99999), notes: []}
]);
const addNoteForCategory = (name, content, categoryId) => {
const chosenCategory = categories.find((category) => category.id === categoryId)
setCategory([...chosenCategory.notes, {
noteTitle: name,
noteContent: content,
id: Math.floor(Math.random()* 99999)
}])
}
}