Answer the question
In order to leave comments, you need to log in
How to add element to array in react object?
Conditionally there is such a state
const [filter, setFilter] = useState({type:"", duration: []});
Answer the question
In order to leave comments, you need to log in
const { duration } = filter;
setFilter({
...filter,
[ ...duration, 1, 2, 3 ], // добавили в массив 1, 2 и 3
});
// теперь state станет
// { type:"", duration: [1, 2, 3] }
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question