Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[이상조] 3장: 리액트 훅 깊게 살펴보기 #38

Merged
merged 2 commits into from
Jan 17, 2024
Merged

Conversation

sjoleee
Copy link
Member

@sjoleee sjoleee commented Jan 2, 2024

늦었다고 생각할 때가 가장 빠를 때다

Copy link
Member

@hyesungoh hyesungoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

너무 빠르다

Comment on lines +48 to +58
```ts
// asis
const imageUploadButtonRef = useRef<HTMLInputElement | null>(null);

// tobe
const imageUploadButtonRef = useRef<HTMLInputElement>(null);
```

useRef는 여러가지 타입으로 사용되는데, 작성해주신 것처럼 초기값과 제네릭이 같으면 MutableRefObject인가 그걸로 추론됩니다.
MutableRefObject는... 상태 대신에 ref를 사용할 때와 같이 어떤 변수를 담아놓을때 사용하게 되는데요, ref.current = "??" 뭐 이런식으로 current에 들어가는 데이터를 정할 수 있습니다.
반면에 RefObject는 current가 readonly입니다. 특정 DOM을 조작하거나 할때는 current를 맘대로 변경하는게 아니고 단순히 참조만 하는거니까는 RefObject가 더욱 적합하지 않을까요?!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이야 맛있다 !!

Comment on lines +76 to +79
## useImperativeHandle

- 자식에게 forwardRef로 ref를 넘겨줄때, 자식이 부모에게 함수를 넘겨줄 수 있는 훅이다.
- 사용이 권장되지 않는 훅으로 알고있다.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

왜 권장되지 않는 것이여요????

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제 기억으로 예전 문서에는 쓰지말라고만 나와있고 이유에 대해서는 기재되어있지 않았던 것 같습니다
제 뇌피셜로는 리액트가 단방향 데이터흐름을 지향하기때문에 그것을 거스르는 이 훅을 사용하지 말라고 한게 아닐까 싶습니다...
혹은 이걸 사용함으로써 자식과 부모간의 결합이 강해져서 그런것일수도...?

4장/README.md Outdated
Comment on lines 12 to 13
- https://www.epicweb.dev/why-i-wont-use-nextjs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://leerob.io/blog/using-nextjs

이것도 추가해줘잉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d7c02db 추가완료

Copy link
Member

@Seojunhwan Seojunhwan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

야미

@hyesungoh hyesungoh merged commit fb734ed into main Jan 17, 2024
1 check passed
@hyesungoh hyesungoh deleted the 3장/이상조 branch January 17, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants