0

I have a api with rtk (redux-toolkit) with a state 'search'


const [search, setSearch] = useState({nexToken: null})

const { data, isLoading, isError } = useGetPostQuery(search ?? skipToken)

useEffect(() => {
 console.log('data', data)
}, [data])

When I call methods to add parameters to my search and set the new state does not happen again the api, why?

for example:


const addCity = () => {
 const newFilter = { city: 'London. }
 setSearch({...search, ...newFilter})
}

fabio87
  • 65
  • 6
  • This should generally work. I assume that you are omitting some code that might be important for this. Could you add some more code? Also, add a `console.log(search)` after your `useState` to make sure state actually changes. – phry Nov 03 '21 at 10:25
  • console.log(search) // {city: 'London', nextToken: null} – fabio87 Nov 03 '21 at 10:33
  • And then it makes a request I assume - what exactly is the behaviour you expect and what is happening? – phry Nov 03 '21 at 11:30
  • expect: when I set a new search that launches a new call api. But now it does not perform an API call. Now I resolved with useLazy – fabio87 Nov 03 '21 at 14:23

0 Answers0