Lets assume I have defined my React state using hooks like that
const items = [{name: 'Jack', age: 1},{name: 'Bill', age: 2},{name: 'Jason', age: 4}];
const [content, setContent] = useState<{name: string, age: number}[]>(items);
What is the best way to modify second element of the array?
This is the way how I am doing it at the moment
const newContent = content.map((item,i) => {
if(i == 1){
return(...item, age: 5)
}
else{
return item;
}
})
setContent(newContent)
Thanks