Home > Blockchain >  REACT Js, prevState not saving the previous state in an object
REACT Js, prevState not saving the previous state in an object

Time:02-19

I'm having a problem that I can't solve. I have an empty object saved in a useState, which I have to fill dynamically according to some filters to do a search in an API. When I choose a filter it has no problems, it saves it for me. But when I choose a second filter, it deletes the previous one and saves the new filter. I am using: https://ant.design/components/table/

useState

const [savedFilters, setSavedFilters] = useState({})

onValuesChange

 <Form
            form={form}
            onValuesChange={e => setSavedFilters(
                prevState => ({...prevState, e })
            )}
>

If anyone could help me I would appreciate it!

CodePudding user response:

did you try to spread 'e' ?

   onValuesChange={e => setSavedFilters(
                prevState => ({...prevState, ...e })
            )}

I would be nice if you told us what value is in savedFilters after update

  • Related