index.js
ReactDom.render(
<BrowserRouter>
<App />
</BrowserRouter>, document.getElementById('root'))
<Routes>
<Route path="/" element={<HomePage />} />
</Routes>
<Link to="/about">About</Link>
<Routes>
<Route path="/" element={<App />} />
<Route index element={<Home />} />
<Route path="teams" element={<Teams/>} />
<Route path=":teamId" element={<Team />} />
</Routes>
const navigate = useNavigate();
navigate('/home');
강의에서는 아래와 같이 페이지별 폴더 생성하고, Index.jsx 생성함
/src/pages/DetailPage/index.jsx
/src/pages/MainPage/index.jsx
나는 기존에 /src/pages/PageName.jsx 와 같이 직접 생성했었음
const formatStats = ([
statHp,
statATK,
statDEP,
statSATK,
statSDEP,
statSPD
]) => [
{name: 'Hit Points', baseStat: statHp.base_stat},
{name: 'Attack', baseStat: statATK.base_stat},
{name: 'Defence', baseStat: statDEP.base_stat},
{name: 'Special Attack', baseStat: statSATK.base_stat},
{name: 'Special Defence', baseStat: statSDEP.base_stat},
{name: 'Speed', baseStat: statSPD.base_stat}
]
const DamageRelations = awiat Promise.all(
types.map(async (i) => {
const type = await axios.get(i.type.url);
return type.data.damage_relations
})
)
=const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
setIsLoading(true);
fetchPokemonData(params.id);
}, [params]);
{(!isLoading && !pokemon) && (
<div>Not Found</div>
)}
✅ 참고
useEffect
에서 deps 배열이 없다면 어떤 state든 변경될 때 실행된다!
const [value, setValue] = useState("");
const renderCountRef = useRef(0);
useEffect(() => {
renderCountRef.current++;
})
const inputRef = useRef();
const handleClick = () => {
inputRef.current.focue();
}
...
return (
<input ref={inputRef} />
)
const ChildComponent = (props, ref) => {
return <input ref={ref}/>
}
export default forwardRef(ChildComponent);