2024-03-08.md
๐กDIL: ๋ชจ๋ ๋ฆฌ์กํธ ๋ฅ ๋ค์ด๋ธ, 1์ฃผ์ฐจ-5
์คํฐ๋: ์๊ฐ CS, https://github.com/monthly-cs/2024-03-modern-react-deep-dive
์ค๋ ์งํ: ๊ฐ์ธ๊ณต๋ถ
DIL-week1-5_2024-03-08
| DIL ์ฃผ์ฐจ | ๋ฒ์ | ๋ด์ฉ | ์ค๋์ฐจ ์ง๋ | | -------- | ------ | ------------------------------ | ----------- | | 1์ฃผ์ฐจ | 1, 2์ฅ | ๋ฆฌ์กํธ ํต์ฌ์์์ ์๋ฐ์คํฌ๋ฆฝํธ | 144p~159p |
์ค๋ ์ฝ์ ๋ด์ฉ์ markdown์ผ๋ก ๊ฐ๋จํ ๋ฉ๋ชจ
์ฝ์ ์๊ฐ: 9์~12์, ํด๋์ค ์ปดํฌ๋ํธ ์์ ๋ง๋ค์ด๋ด๐ค
ํด๋์ค ์ปดํฌ๋ํธ
class MyComponent extends React.Component: <MyProps, MyState> {
constructor(props: MyProps) {
super(props)
this.state = {
count: 0
}
}
...
}
public render() {
const {
props: { required, text },
state: { count, isLimited },
} = this;
return (
<div>{count}</div>
)
}
- class ์ปดํฌ๋ํธ์ constructor๋
- state์ ์ด๊ธฐํ ํ๋ค
- props๋ฅผ super์ ์ ๋ฌํ๋ค
- constructor ์์ด state์ ์ด๊ธฐํ?
ES2022
์ class field- @babel/plugin-proposal-class-properties๋ก ํธ๋์คํ์ผ ํด์ผํจ
์๋ช ์ฃผ๊ธฐ ๋ฉ์๋
-
React 17 ์ด์ ์ unsafe ๋ฉ์๋?
- UNSAFE_componentWillMount()
- UNSAFE_componentWillReceiveProps()
- UNSAFE_componentWillUpdate()
-
Life Cycle Method ์คํ๋๋ ์์
- mount
- update
- unmount
-
render()
- mount, update
- ์์ ํจ์ no side-effects
-
componentDidMount()
- ๋ง์ดํธ ํ > this.setState ํธ์ถ ์? ์ฆ์ ๋ค์ ๋๋๋ง >> ๋ธ๋ผ์ฐ์ ๊ฐ ์ค์ ๋ก UI๋ฅผ ์ ๋ฐ์ดํธ ํ๊ธฐ ์ ์ ์คํ
- ์ฑ๋ฅ ๋ฌธ์ ๊ฐ ์์ ์ ์์ > ๊ผญ ํ์ํ ์์ ๋ง ex) API ํธ์ถ ํ ์ ๋ฐ์ดํธ, DOM ์์กด
-
componentDidUpdate()
- ์กฐ๊ฑด๋ฌธ์ผ๋ก ํ์ถํ์ง ์์ผ๋ฉด? this.setState ๊ณ์ ํธ์ถ
-
componentWillUnmount()
- ํด๋ฆฐ์ , this.setState ํธ์ถx
-
shouldComponentUpdate()
- state์ด๋ props์ ๋ณ๊ฒฝ์ผ๋ก ์ธํด ๋ฐ์ํ๋ ๋ฆฌ๋๋๋ง์ ๋ง์ ์ ์๋ค
-
getDerivedStateFromError()
- ์๋ฌ ๋ฐ์ด๋๋ฆฌ ๋ง๋ฆ
- ๋๋๋ง ๊ณผ์ ์์ ํธ์ถ๋๋ฏ๋ก, side-effect ์์ผ๋ฉด ์๋๋ค. (error state ๋ฐํ ์ธ์ ๋ชจ๋ ๊ฒ, ๋ก๊น ๋ ์๋จ)
-
componentDidCatch
- ์ปค๋ฐ ๋จ๊ฒ์์ ํธ์ถ๋๋ฏ๋ก, side-effect๋ฅผ ์ํํ ์ ์๋ค
- ์๋ฌ ๋ก๊น