Jotai?
Jotai는 Recoil에 영감을 받아 만들어진 상태 관리 라이브러리이다.
Jotai는 미니멀 API를 지향하며, TypeScript 기반이다. React의 useState와 유사하게 사용이 가능하다.
useSetAtom, useAtomValue를 통해 리렌더링 문제를 줄일 수 있다.
모든 상태는 전역적으로 접근가능하다!!
jotai 정말 기본적인 사용 방법.
1. atom
const countAtom = atom(0);
atom(state)를 생성하고, 초기값을 괄호안에 넣는다.
2. useAtom( read / write )
const [count, setCount] = useAtom(countAtom);
1에서 생성한 atom 을 불러와 useState 와 동일하게 사용 가능하다.
3. useSetAtom( write )
const setCount = useSetAtom(countAtom);
atom 의 값을 update 할 때 사용한다.
4. useAtomValue(read)
const count = useAtomValue(countAtom);
atom 의 값을 read 할 때 사용한다.
useSetAtom, useAtomValue는 useAtom과는 다르게 리렌더링이 발생하지 않는다.
'기록 > TIL' 카테고리의 다른 글
2023.08.22 - lodash로 편하게 Throttle 사용하기 (0) | 2023.08.22 |
---|---|
2023.08.21 - TypeScript url 파라미터로 request를 보내기 위해 배열로 받기, react does not recognize the `~~~` prop on a DOM element. (0) | 2023.08.21 |
2023.08.17 - git에서 특정 브랜치만 clone하기 (0) | 2023.08.17 |
2023.08.16 - Supabase의 TimeZone 세팅 (0) | 2023.08.16 |
2023.08.14 - 배포 시 console, warning, error 지우기 (0) | 2023.08.14 |