Why my useState, does not work property? In a filter search bar, I'm trying to reprint the elements of an Array depending on the input but I can't get the reprinting right,
const clickSearchIcon = (query) => {
let filteredItems = [];
console.log('ITEAM ALL:', itemsAll); //works --> 9
setItems(itemsAll); //DONT work, --> 1st time: 9 , second time: 0; both times must be 9
console.log('items:', items);
//filtrar items que concuerdan con el query
items.map((item) => {
if (item.title === query) return filteredItems.push(item);
});
//repintar item filtrado con el query
setItems(filteredItems); //does work
};
this is the complete file, in case you need more context