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") ?? "";

Explanation

The URL is state that users can bookmark and share, and Back/Forward works naturally. Loaders and query keys can derive from it.

Further reading

Problem with a question

State Management · Junior · question 70

Test yourself

Take the State Management · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz