0

I have two objects:

filter: {
   brand: [],
   size: [],
   orderBy: 1,
   page: 1,
   pageSize: 15,
   search: search,
   condition: [],
   gender: [],
   offeredBy: [],
   color: []
};

tmpFilters: {
   brand: [],
   size: [],
   orderBy: 1,
   page: 1,
   pageSize: 15,
   search: search,
   condition: [],
   gender: [],
   offeredBy: [],
   color: []
};

My goal is to set the filters to the value of temporary filters. Here is what I have already tried but not working.

    let newObj = { ...tmpFilters };
    await setFilter(newObj);
    console.log(filter);
    

When I write out the filter in the console, it says that the value wasn't changed. I have check the other answers but nothing seems to work.

Arinton Akos
  • 145
  • 2
  • 10
  • 3
    Your state has been changed, but`setState` does not reflect changes immediately. The new value won't be available until the next render cycle. – pilchard Jul 24 '21 at 10:23
  • 2
    ^^ There's no point using `await` on `setFilter`, state setters don't return promises (or indeed anything else useful). – T.J. Crowder Jul 24 '21 at 10:27

0 Answers0