+ 1

React function hooks

hi, i have try pass a value parent to child but i fail, someone know why the rthe code dont'worck? thank's import React, { useState } from "react"; import ReactDOM from "react-dom"; function MostraValore() { const [valore, setValore] = useState("pippo"); console.log(valore); function cattura(event) { setValore(event.target.value); } return ( <div> <p>Registra valore</p> <Input valore={valore} cattura={cattura} /> <Mostra /> </div> ); } function Input(props) { const { cattura, valore } = props; console.log(valore); return ( <div> <input type="text" valore={valore} onChange={cattura} /> </div> ); } function Mostra(props) { const { valore } = props; console.log(valore); return ( <div> <h2>Questo è il valore </h2> <p>{valore}</p> </div> ); } ReactDOM.render(<MostraValore />, document.getElementById("root")); https://stackblitz.com/edit/react-simple-list-example-zdlbhf?file=index.js

30th Oct 2020, 4:10 PM
Alessio Farroni
Alessio Farroni - avatar
1 Resposta
0
i have resolve and the code is update
31st Oct 2020, 7:38 AM
Alessio Farroni
Alessio Farroni - avatar