i am preparing a query params for an array, but now i would like to have with this format
?vegetable[]=tomato&foo[]=lechuce
this is my current code:
import { useSearchParams } from 'react-router-dom'
const [searchParams, setSearchParams] = useSearchParams()
searchParams.set('vegetable', ['tomato', 'lechuce'])
with that i am getting
?vegetable=tomato%2Clechuce
but i need
?vegetable[]=tomato&foo[]=lechuce
and my other small question is:
how can i add '?' to start to search
i am doing like this:
navigate(location?.pathname + '?' + searchParams.toString())
its necesary use navigate?
useSearchParamsreturns aURLSearchParamsobject