Fully implemented the search function

This commit is contained in:
Dino Tutic 2023-07-13 21:06:19 +02:00
parent e707852e69
commit 8485efc47c
2 changed files with 9 additions and 8 deletions

View File

@ -19,6 +19,7 @@ const appRouter = createBrowserRouter(
<Route index element={<HomePage />} />
<Route path=":type" element={<HomePage />} />
<Route path=":type/:id" element={<PetDetailsPage />} />
<Route path="search" element={<SearchPage />} />
</Route>
)
);

View File

@ -1,20 +1,20 @@
import React, { useState, useEffect } from 'react';
import Hero from '../../components/hero';
import { getPets } from '../../api/petfinder';
import Pet from '../../components/pet';
import React, { useState, useEffect } from "react";
import Hero from "../../components/hero";
import { getPets } from "../../api/petfinder";
import Pet from "../../components/pet";
import { useSearchParams } from "react-router-dom";
// Import useSearchParams
const SearchPage = () => {
// Get searchParams object from useSearchParams
const petNameToFind = 'REPLACE ME'; // Get query parameter using searchParams object
const [searchParams] = useSearchParams();
const petNameToFind = searchParams.get("name"); // Get query parameter using searchParams object
const [pets, setPets] = useState([]);
useEffect(() => {
async function getPetsData() {
const petsData = await getPets('', petNameToFind);
const petsData = await getPets("", petNameToFind);
setPets(petsData);
}