Open dxwwan opened 8 months ago
์ํ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํ ํ
import { useState } from "react"; const MemberList = () => { const [memberList, setMemberList] = useState([ { name: "KingBaedal", age: 10, }, { name: "MayBaedal", age: 9, }, ]); const sumAge = memberList.reduce((sum, member) => sum + member.age, 0); const addMember = () => { setMemberList([ ...memberList, { name: "DokgoBaedal", age: 11, }, ]); } ; };
interface Member { name: string; age: number; }
useEffect ( EffectCallback, deps )
์๋์น ์๋ ์ฌ๋๋๋ง์ ๋ฐ๋ณตํ ์ ์๋ค.
const [name, setName] = useState(""); useEffect(() => { setName("๋ฐฐ๋ฌ์ด") },[]); return ( <div> {`์๋ ํ์ธ์, ${name}๋!`} </div> ); //์ปดํฌ๋ํธ๊ฐ ๋ ๋๋ง ๋ ํ, name์ด ๋น์นธ์ผ๋ก ๋ ๋๋ง //setName์ด ์๋ฃ ๋ ๋ ๊น์ง ๋น์นธ ์ ์ง
useLayoutEffect
useMemo, useCallback
์ด๋ค ๊ฐ์ ๊ณ์ฐํ๋ ๋ฐ ์ค๋ ์๊ฐ์ด ๊ฑธ๋ฆด ๋๋ ๋ ๋๋ง์ด ์์ฃผ ๋ฐ์ํ๋ form์์ ์ฌ์ฉ
type DependencyList = ReadonlyArray<any>; function useMemo<T>(factory: () => T, deps: DependencyList | undefined): T; function useCallback<t extends (...args: any[]) => any>(callback: T, deps:DependencyList):T;
useRef
๐ชํ
1. ๋ฆฌ์กํธ ํ
useState
์ํ๋ฅผ ๊ด๋ฆฌํ๊ธฐ ์ํ ํ
์์กด์ฑ ๋ฐฐ์ด์ ์ฌ์ฉํ๋ ํ
useEffect ( EffectCallback, deps )
์๋์น ์๋ ์ฌ๋๋๋ง์ ๋ฐ๋ณตํ ์ ์๋ค.
useLayoutEffect
useMemo, useCallback
์ด๋ค ๊ฐ์ ๊ณ์ฐํ๋ ๋ฐ ์ค๋ ์๊ฐ์ด ๊ฑธ๋ฆด ๋๋ ๋ ๋๋ง์ด ์์ฃผ ๋ฐ์ํ๋ form์์ ์ฌ์ฉ
useRef
ISSUE