Replies: 1 comment 2 replies
-
안녕하세요! @hywlss9 님! 좋은 주제 감사드려요. 제 기준에서 이것은 팀내의 협의를 통한 일관적인 규칙만 있다면 3개 옵션 모두 괜찮을 것 같아요. 그와 별개로 저는 원시 타입의 경우는 initialState에, 각 타입별 falsy한 값을 넣는 것 같아요. 그거 정도만해도, initialState와 변수명만을 보고 어느정도 유추가 잘 되어서요! function Foo() {
const [open, setOpen] = useState(false)
const [count, setCount] = useState(0)
const [searchText, setSearchText] = useState('')
// ...
} 위 코드 처럼요. 아니면 값이 없다. 같은 상태를 표현할 때는, function Foo() {
const [val, setVal] = useState<SomeValue | null>(null)
// ...
} 위 처럼 나타내고 있어요. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
저는 useState의 initialState가 없으면 초기 값이 undefined라는 걸 알 수 있으니 1번을 주로 사용하는데요,
2번처럼 undefined를 추가하여 더 명시적으로 사용하시기도 하더라구요.
의견이 궁금합니다!
42 votes ·
Beta Was this translation helpful? Give feedback.
All reactions