Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

instant search initial value

const getURLParam = (key = 's') => {
  const urlParams = new URLSearchParams(window.location.search);
  const param = urlParams.get(key);

  return param || '';
};

const App = () => {
// set initial value
const [query, setQuery] = useState(getURLParam());

return (
	<InstantSearch
          searchClient={searchClient}
          indexName="post"
          searchState={{ query }}
        >
          <SearchBox
            onChange={(e) => setQuery(e.target.value)}
          />
        {/* ... */}
     </InstantSearch>
)
}
 
PREVIOUS NEXT
Tagged: #instant #search #initial
ADD COMMENT
Topic
Name
1+2 =