エラーが解消できません。
Invalid value for prop `value` on <input> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM. For details, see https://fb.me/react-attribute-behavior
上記がエラー内容です。
propsのvalueの値が無効と言われているのですがなぜなのでしょうか?
調べてもわからなかったのでわかる人がいましたら教えて欲しいです
//親コンポーネント 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
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。