2022/03/23 TS 리액트에서 event 타입 지정
2022. 3. 20. 21:08ㆍProject : 근의 공식(Muscle Formula)/Error Handling
function Test () {
const [value, setValue] = useState('');
const handleInputValue = (e :React.ChangeEvent<HTMLInputElement>) => {
setNumber(e.target.value);
}
return (
//...
<input type="text" placeholder="값을 입력해주세요" onChange={handleInputValue}/>
//...
)
}
해결책 : 이벤트(e)의 타입을 제대로 지정해준다. VS Code 참조해서 쓰면 알기 쉽다.
Type 'ChangeEvent<HTMLInputElement>' is not assignable to type 'ChangeEvent<HTMLSelectElement>' in React js?
I am passing an onChange event as a props to a component But I am getting datatype error. Parent Component - const onChangeStatus=(selectType:string , e:React.ChangeEvent<HTMLSelectElement>) ...
stackoverflow.com
'Project : 근의 공식(Muscle Formula) > Error Handling' 카테고리의 다른 글
| 2022/03/22 styled-component에서 :checked가 안될 때 (0) | 2022.03.22 |
|---|---|
| 2022/03/22 별점 input 태그 쓰기와 value 가져오기 (0) | 2022.03.22 |
| 2022/03/20 input 태그 에러 : input is a void element tag and must neither have `children` nor use `dangerouslySetInnerHTML` (0) | 2022.03.20 |
| 2022/03/17 react-router-dom에서 Switch를 찾을 수 없는 오류 (0) | 2022.03.17 |
| 2022/03/17 git 관련 문제 해결 (0) | 2022.03.17 |