Trying to add search function / useNavigate question

This commit is contained in:
Dino Tutic 2023-07-13 20:57:06 +02:00
parent 24b9860d18
commit e707852e69

View File

@ -1,11 +1,11 @@
import React, { useRef } from 'react';
import React, { useRef } from "react";
import { createSearchParams, useNavigate } from "react-router-dom";
// Import createSearchParams
// Import useNavigate
const Search = () => {
// get navigate function
const navigate = "REPLACE ME";
const navigate = useNavigate();
const searchInputRef = useRef();
@ -13,13 +13,14 @@ const Search = () => {
e.preventDefault();
const searchQuery = {
name: searchInputRef.current.value
}
name: searchInputRef.current.value,
};
// use createSearchParams
const query = "REPLACE ME";
const query = createSearchParams(searchQuery);
// imperatively redirect with useNavigate() returned function
navigate({ pathname: "/search", search: `${query}` });
};
return (