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 path=":type" element={<HomePage />} />
|
||||
<Route path=":type/:id" element={<PetDetailsPage />} />
|
||||
<Route path="search" element={<SearchPage />} />
|
||||
</Route>
|
||||
)
|
||||
);
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user