Trying to add search function / useNavigate question
This commit is contained in:
parent
24b9860d18
commit
e707852e69
@ -1,11 +1,11 @@
|
|||||||
import React, { useRef } from 'react';
|
import React, { useRef } from "react";
|
||||||
|
import { createSearchParams, useNavigate } from "react-router-dom";
|
||||||
// Import createSearchParams
|
// Import createSearchParams
|
||||||
// Import useNavigate
|
// Import useNavigate
|
||||||
|
|
||||||
const Search = () => {
|
const Search = () => {
|
||||||
|
|
||||||
// get navigate function
|
// get navigate function
|
||||||
const navigate = "REPLACE ME";
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const searchInputRef = useRef();
|
const searchInputRef = useRef();
|
||||||
|
|
||||||
@ -13,13 +13,14 @@ const Search = () => {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const searchQuery = {
|
const searchQuery = {
|
||||||
name: searchInputRef.current.value
|
name: searchInputRef.current.value,
|
||||||
}
|
};
|
||||||
|
|
||||||
// use createSearchParams
|
// use createSearchParams
|
||||||
const query = "REPLACE ME";
|
const query = createSearchParams(searchQuery);
|
||||||
|
|
||||||
// imperatively redirect with useNavigate() returned function
|
// imperatively redirect with useNavigate() returned function
|
||||||
|
navigate({ pathname: "/search", search: `${query}` });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user