Programming/React

[React] Hello, React

stein 2022. 2. 7. 15:07

Q&A

 

Q1. custom hook은 component와 큰 차이가 없어보인다. 무엇이 다른가?

 

 

what's the difference between components and custom hooks?

here is my code function Label({title}){ return <h1>{title}</h1> } function useLabel({title}){ return <h1> {title}</h1> } function Diff(){ return <div> <...

stackoverflow.com

A1.

https://stackoverflow.com/questions/67454288/whats-the-difference-between-components-and-custom-hooks

Custom hook typically refers to a function that calls one or more of the built in hooks provided by react, such as useState, or useEffect.

 

https://dev.to/sevenzark/why-you-should-be-writing-react-custom-hooks-5egl

The difference between a custom hook and a component is that a custom hook will return values, not React components or markup

Q2. hook을 조건문 안에 넣으면 어떻게 문제가 발생하는가?

https://ko.reactjs.org/docs/hooks-rules.html

 

Hook의 규칙 – React

A JavaScript library for building user interfaces

ko.reactjs.org

 

'Programming > React' 카테고리의 다른 글

[React] styled-component(css-in-js)에서 transition 효과  (0) 2022.02.10