1

I am totally new to using RTK-query, I was looking for the possibilities of using debounce and RTK-query when searching for a specific element by value. The question is not even how to use RTK-query together with debounce, but do I really need debounce? when I use RTK-query or can i configure RTK-query itself? i can't find anything about it other than How to implement rtk's createApi query for debouncing this is an answer yes that seems to be the solution but is there a better approach ? If so, could you please clarify this situation for me a bit or what section of the documentation I need to read, is there such a section at all?

thank you

songhee24
  • 129
  • 9
  • You don't have to do debouncing with rtk query all the time. However, it may help you to achieve better performance (avoiding excessive API calls or costly state updates), so you might consider it for certain use cases. – Yevhen Horbunkov Dec 07 '22 at 18:54
  • @YevhenHorbunkov hello thanks for the hint, yes I am trying to use the debounce value when searching by the name of certain elements to improve performance could you tell me if there is a better way to implement the debounce using rtk query – songhee24 Dec 08 '22 at 05:00

1 Answers1

2

looks like i found a solution

import { useDebounce } from 'use-debounce'
import { skipToken } from '@reduxjs/toolkit/query'

const [storeName, setStoreName] = useState('')
const [searchTerm] = useDebounce(storeName, 1500)


const { data } = useSearchStoresRequestQuery(searchTerm || skipToken)

I don't know how correct this is but I just give skipToken as parameters if the value I'm looking for is empty

https://redux-toolkit.js.org/rtk-query/api/created-api/hooks#skiptoken

songhee24
  • 129
  • 9