I am trying to have the SigninForm pass the email back to the component that called it (App). Then when email is updated App should re-render. I tried to create the structure given in an earlier question. However I could not get the App component to update and display the email in my React code.
TLDR: Why isnt the Email displaying on the snippet when I click the button?
function App() { const [email, setEmail] = React.useState(); return ( <div> EMAIL: {email} <br></br> <SigninForm setEmail={setEmail}/> </div> ) } function SigninForm() { const [email, setEmail] = React.useState() var credsSubmit = (event) => { event.preventDefault(); setEmail('[email protected]') } return ( <div> <form onSubmit={credsSubmit}> <input type='submit' /> </form> </div> ) } ReactDOM.render(<App />, document.getElementById('root')); <script crossorigin src="https://unpkg.com/react@16/umd/react.production.min.js"></script> <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.production.min.js"></script> <div id="root"></div>
Appupdate?SigninFormis not using any props and has its own state