useIsFocused

Tags
re-render
  • focused 될 때 호출됨.
  • focused 상태인지 true/false 반환.
  • (focused state가 바뀌므로) focused 될 때마다 스크린을 re-render 시킴.
  • 무겁다면 React.memo 또는 React.PureComponent로 re-render를 최소화 시켜야 함.
 
import * as React from 'react'; import { Text } from 'react-native'; import { useIsFocused } from '@react-navigation/native'; function Profile() { // This hook returns `true` if the screen is focused, `false` otherwise const isFocused = useIsFocused(); return <Text>{isFocused ? 'focused' : 'unfocused'}</Text>; }