Learn React with TypeScript - Second Edition by Carl Rippon

Learn React with TypeScript - Second Edition by Carl Rippon

Author:Carl Rippon
Language: eng
Format: epub
Publisher: Packt Publishing Pvt. Ltd.
Published: 2023-02-21T00:00:00+00:00


We no longer need setSearchParams because the setting of the search parameter is included in the navigation path, so remove this from the useSearchParams call: const [searchParams] = useSearchParams();

In the running app, enter some search criteria in the search box and press Enter to submit the search.

The search parameter is used to navigate to the products list page. When the products list page appears, the correctly filtered products are shown:

Figure 6.15 – Products list page with filter products

So, programmatic navigation is achieved using the useNavigate hook. This returns a function that can navigate to the path passed into it.

For more information on the useNavigate hook, see the following link in the React Router documentation: https://reactrouter.com/en/main/hooks/use-navigate.

Next, we will refactor the search form’s navigation to use React Router’s Form component.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.