Frontend/React
[ERROR] react_devtools_backend_compact.js:13851 Warning: Failed prop type: Invalid prop `onChange` of type `boolean` supplied to `ForwardRef(TextField)`, expected `function`.
신림쥐
2024. 9. 19. 14:09
728x90
오류 메시지
react_devtools_backend_compact.js:13851 Warning: Failed prop type: Invalid prop `onChange` of type `boolean` supplied to `ForwardRef(TextField)`, expected `function`.
원인
- value로 받는 타입과 리턴으로 받는 타입이 일치하지 않아서 발생하는 메시지이다.
- 정해진 타입으로 받을 수 있도록 코드를 수정해야 한다.
해당 코드
const value: string;
onChange: (_e: React.ChangeEvent<HTMLInputElement>) => void;
const handleChange = () => {
if (maxLength) {
if (value.length > maxLength) {
return false;
}
}
return onChange;
};
수정 코드
const value: string;
onChange: (_e: React.ChangeEvent<HTMLInputElement>) => void;
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (maxLength) {
if (e.target.value.length > maxLength) return;
}
if (onChange) {
onChange(e);
}
};
728x90