Programing/React
[React Native] Lifecycle of Class Component
mjune.kim
2024. 2. 13. 13:06
getDerivedStateFromProps(props, state) : 상태 또는 파라미터 변경 후 기존에 생성되었던 컴포넌트 오브젝트의 render() 를 호출시 해당 변경된 값들을 반경시킬때 사용할 수 있다.
static getDerivedStateFromProps(props, state) { if (state.key != props.route.params.key) { return new_state; // { key: new_value, ... } } else { return null; } } Prop object: ![]() State: Class component 의 state object (e.g., this.state = {key: value}) |