<CheckInput
ref={refPassword}
label='Password'
placeholder='Password'
returnKeyType='done'
value={password}
onChangeText={setPassword}
/>
컴포넌트 자체에다가 ref를 설정해주니 아래와 같은 오류가 발생했다.
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
경고 메시지에서 안내하고 있듯이 리액트에 forwardRef를 사용해주면 된다.
forwardRef를 import해준다.import React, { useState, forwardRef } from 'react';
(...)
const CheckInput = forwardRef(//forwardRef로 감싸주기
({ props }, ref) => {//두번째 파라미터로 ref를 넣어주기
return (
<Container>
<StyledInput
ref={ref}
/>
</Container>
);
}
);