handleInputChangeという関数を親で定義して子でpropsとして表示せせたいのですが下記のエラーになります。
handleInputChangeの型定義も子コンポーネントで定義しています。
Failed prop type: Invalid prop `onChange` of type `boolean` supplied to `ForwardRef(TextField)`, expected `function`.
//親コンポーネント import React, { useState } from 'react' type Props { texts: ItemList[] } interface ItemList { id: number text: string } // inputFormに文字を入力しているとき (TextInput(子)に渡したい) const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => { setInputTitle(e.target.value) } const App: React.FC = () => { const [task, setTask] = useState('') const [ count, setcount ] = useState(0) return ( <div> <TextInput = text={task} handleInputChange={handleInputChange} /> </div> ) }
子コンポーネント import React, from 'react' interface Props { text: string handleInputChange: React.ChangeEvent<HTMLInputElement> } const TextInput: React.FC<Props> = (text,handleInputChange) => { } return ( <div> <div className="inputForm"> <div className="inner"> <input type="text" className="input" value={text} onChange={handleInputChange} /> </div> </div> </div> ) } export default TextInput

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/17 05:36
2020/01/17 05:37