Created
September 6, 2022 13:37
-
-
Save solanoize/bcea6d433e1b9a6c0853c8c795691d64 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { useState } from 'react'; | |
| import ReactDOM from 'react-dom/client'; | |
| function BelajarForm() { | |
| const [nama, setNama] = useState("John Doe") | |
| const [message, setMessage] = useState(""); | |
| const handleSubmit = (e) => { | |
| e.preventDefault(); | |
| if (nama !== "") { | |
| console.log("Nama saya adalah " + nama) | |
| } else { | |
| setMessage("Ups.. harus di isi cui!") | |
| } | |
| } | |
| return ( | |
| <form onSubmit={handleSubmit}> | |
| <label>Masukan nama:</label> | |
| <input | |
| type="text" | |
| value={nama} | |
| onChange={(e) => setNama(e.target.value)} | |
| /> | |
| <small>{message}</small> | |
| <p>Nama saya: {nama}</p> | |
| <button type='submit'>Save</button> | |
| </form> | |
| ) | |
| } | |
| const root = ReactDOM.createRoot( | |
| document.getElementById('root') | |
| ); | |
| root.render(<BelajarForm />); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment