0

I have an array of objects and I want to update a value within those objects using the useState hook, but unclear on how to format this and get it working.

setCarUnsubscribeList(carUnsubscribeList => (carUnsubscribeList.forEach((car:CarSelections) => {
  car.checked = true;
})));
1
  • does it occur any error? Commented Nov 30, 2020 at 18:26

1 Answer 1

1

spread the original object and change the propert you want

setAllChecked(prev => prev.map(car =>({
    ...car,
    checked : true
})))
Sign up to request clarification or add additional context in comments.

1 Comment

I use TypeScript and am getting this error, when using this format: 'Type 'void' is not assignable to type 'CarSelections[]''.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.