[React] Hooks 기초 개념

정예원·2021년 11월 30일
0

React

목록 보기
4/7

추가 정리 예정

useState, useEffect에 대해서 알아보자.

앱을 리액트 훅으로 만들면, class component, did mount, render..를 안해도 된다.
모든것은 하나의 function이 된다. = 함수형 프로그래밍 스타일이 된다.

hook은 recompose에서 시작되었다.
react에게 인수되었다.
이후 더 쉬워졌다.

useState

const [count, setCount] = useState(0);

return (
	<>
          {count}
          <button onClick={() => setCount(count+1)}>Increment</button>
    	</>
)

A, setA는 관습이다.
위와 같은 규칙으로 적지 않아도 동작한다.

코드가 매우 간결해진다.

useEffect

component did mountk, did update와 비슷하다.
주로 API에서 데이터를 요청할 때 사용된다.

profile
hello world!

0개의 댓글