Fully implemented the search function
This commit is contained in:
parent
e707852e69
commit
8485efc47c
@ -19,6 +19,7 @@ const appRouter = createBrowserRouter(
|
|||||||
<Route index element={<HomePage />} />
|
<Route index element={<HomePage />} />
|
||||||
<Route path=":type" element={<HomePage />} />
|
<Route path=":type" element={<HomePage />} />
|
||||||
<Route path=":type/:id" element={<PetDetailsPage />} />
|
<Route path=":type/:id" element={<PetDetailsPage />} />
|
||||||
|
<Route path="search" element={<SearchPage />} />
|
||||||
</Route>
|
</Route>
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
import React, { useState, useEffect } from "react";
|
||||||
import Hero from '../../components/hero';
|
import Hero from "../../components/hero";
|
||||||
import { getPets } from '../../api/petfinder';
|
import { getPets } from "../../api/petfinder";
|
||||||
import Pet from '../../components/pet';
|
import Pet from "../../components/pet";
|
||||||
|
import { useSearchParams } from "react-router-dom";
|
||||||
// Import useSearchParams
|
// Import useSearchParams
|
||||||
|
|
||||||
const SearchPage = () => {
|
const SearchPage = () => {
|
||||||
|
|
||||||
// Get searchParams object from useSearchParams
|
// Get searchParams object from useSearchParams
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
const petNameToFind = 'REPLACE ME'; // Get query parameter using searchParams object
|
const petNameToFind = searchParams.get("name"); // Get query parameter using searchParams object
|
||||||
|
|
||||||
const [pets, setPets] = useState([]);
|
const [pets, setPets] = useState([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function getPetsData() {
|
async function getPetsData() {
|
||||||
const petsData = await getPets('', petNameToFind);
|
const petsData = await getPets("", petNameToFind);
|
||||||
|
|
||||||
setPets(petsData);
|
setPets(petsData);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user