본문 바로가기
Study Note/React

React #Rules of Hooks

by 시뮝 2022. 9. 24.
728x90

React Rules of Hooks

 

Only call React Hooks in React Functions

  1. React Component Functions
  2. Custom Hooks

 

Only call React Hoos at the Top Level

  1. Don't call them in nested functions
  2. Don't call them in any block statements

 

+ extra, unoffical Rule for useEffect(): ALWAYS add everything you refer to inside of useEffect() as a dependency

useEffect(() => {
  setFormIsValid(email && password)
}, [email]); // (x)

useEffect(() => {
  setFormIsValid(email && password)
}, [email, password]); // (o)
728x90

'Study Note > React' 카테고리의 다른 글

React #Redux  (0) 2022.09.24
React #Building Custom Hooks  (0) 2022.09.24
React #Understanding useReducer()  (0) 2022.09.24
React #mongoose #페이지네이션 구현  (0) 2021.03.17
React #joi 로 유효성 검증하기  (0) 2021.03.17

댓글