creating a copy of state in react code example

Example: copying state to object and editing it vs setting state

//Setting State through produce

setFilters((filters) => (
       	produce(filters, draftFilters => {
            if (param[0] === 'availability') {
              draftFilters.availability = param[1]
            } else {
              draftFilters[param[0]] = parseInt(param[1], 10)
            }

//Copying to obect, then editing the object

const params = produce(filters, draftFilter => {
      draftFilter.page = page + 1;
    })
    
//In this case, we're not updating the state. Just updating the object params.

Tags:

Misc Example