import {data} from "../assets/data/data";
import {Link} from "react-router-dom";
function Main() {
return(
<>
<ul>
{data.map(el => <li key={el.id}>
<Link to={`/detail/${el.id}`}>
<img src={el.img}/>
<div>{el.name}</div>
</Link>
</li>)}
</ul>
</>
);
}
export default Main;
import { useParams } from "react-router-dom";
import {data} from "../assets/data/data";
function Detail() {
const params = useParams();
const animalData = data.find((el) => {
return el.id === Number(params.id)
});
return(
<>
<section className="detail">
<img src={animalData.img}/>
<h2>{animalData.name}</h2>
<div>{animalData.description}</div>
</section>
</>
);
}
export default Detail;
import { Link, useSearchParams } from "react-router-dom";
import {data} from "../assets/data/data";
import {getRegExp} from "korean-regexp";
function Search() {
const [searchParams] = useSearchParams();
const param = searchParams.get('animal')
const reg = getRegExp(param);
const filterdData = data.filter((el)=>el.name.match(reg));
return(
<>
<ul>
{filterdData.map(el => <li key={el.id}>
<Link to={`/detail/${el.id}`}>
<img src={el.img}/>
<div>{el.name}</div>
</Link>
</li>)}
</ul>
</>
);
}
export default Search;
npm install korean-regexp
'자기계발' 카테고리의 다른 글
함수형 컴포넌트 생명주기 (0) | 2024.09.13 |
---|---|
클래스 컴포넌트 생명주기 (0) | 2024.09.13 |
SPA & MPA 와 CSR & SSR 이란?? (0) | 2024.09.02 |
모던 자바스크립트 Deep Dive 13장 (0) | 2024.08.28 |
얼렁뚱땅 컴공과 데스크셋업 (0) | 2024.08.08 |