π§
[React] render methods should be a pure function of props and state
purpplee
2021. 12. 3. 10:51
render methods should be a pure function of props and state
render λ΄μ setState λ±μ νΈμΆν΄μ κ³μ λ λλ§ λλ©΄ μ΄λ° μ€λ₯κ° λ¬λ€. λ νΈμΆν μ μλλ°...?! μκ³ λ³΄λ μμ μ»΄ν¬λνΈλ‘ setState νλ function μ props λ‘ μ λ¬ν΄μ€ λ€, onClick μ ν λΉν΄μ€¬λλ°.... μ΄λ° ννλ‘ ν λΉν΄μ€μ μκΈ΄ λ¬Έμ μλ€.
handleClick = (e) => {
this.setState({value:e});
}
onClick={handleClick(value)}
handleClick(value) λ ν¨μ μ€νλ¬Έμ΄λ€!!!! λ ν¨μλ₯Ό μ€ννκ³ μμλ κ²μ΄λ€.... λ°λΌμ μλμ²λΌ μμ ν΄μ€μΌ νλ€.
handleClick = (e) => {
this.setState({value:e});
}
onClick={() => handleClick(value)}
λ°μν