State Management · Junior · Question 70 of 75
Where should a search box's query live so the page can be shared and survives reload?
const [searchParams, setSearchParams] = useSearchParams();
const q = searchParams.get("q") ?? "";- ✓Correct answer: In the URL search params, e.g. via
useSearchParams - 2In a
useRef - 3In
sessionStorageonly
Explanation
The URL is state that users can bookmark and share, and Back/Forward works naturally. Loaders and query keys can derive from it.