Мне нужно чтобы при нажатии на букву она добавлялась в value в инпут в компоненту выше:
основа:
function App() {
const [value, setValue] = useState('');
return (
<div className="App">
<main>
<div className="gliph">
<div className="gliphArea">
<h1>Gliphs</h1>
<input className="inputLine" value={value} readOnly />
<div className="gliphAlphabet">
<Gliph value={value} set={() => setValue()} />
</div>
</div>
</div>
</main>
<div className="history">
<input type="text" className="inputLine" readOnly />
</div>
</div>
);
}
Дочерний компонент:
const alphabet = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
const Gliph = ({ value, set }) => {
const handleClick = (letter) => {
set(value + letter);
}
return (
<>
{alphabet.map(l => <div key={l} className="gliphMine" onClick={() => handleClick(l)}>{l}</div>)}
</>
)
}
Код ошибки:
A component is changing a controlled input to be uncontrolled. This is likely caused by the value changing from a defined to undefined, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component.
Когда это он стаёт неконтроллируемым?