study: 리네다기 | 8장 - 자식 컴포넌트에 ref 설정 (React.forwardRef())

Lumpen·2023년 5월 6일
0

Study

목록 보기
73/92

자식 컴포넌트 내에서 Props 로 받은 ref 를
사용 후

React.memo 와 같이
자식 컴포넌트를
React.forwardRef 로 감싸 export 하여
사용할 수 있다

const BorderedInput = ({hasMarginBottom, ...rest}: Props, ref) => {
  return (
    <TextInput
      style={[styles.input, hasMarginBottom && styles.margin]}
      {...rest}
      ref={ref}
    />
  );
};

export default React.forwardRef(BorderedInput);
profile
떠돌이 생활을 하는. 실업자는 아니지만, 부랑 생활을 하는

0개의 댓글