I want the user to input some text, click submit and the text will be displayed below. I was able to get the input text as a whole, and print it in console. But I don't know how to display the text.
Here's my code: https://codesandbox.io/s/ecstatic-curie-ej6og?file=/src/App.js
import React, { useState } from "react";
import "./styles.css";
export default function App() {
const [enteredText, setEnteredText] = useState("");
const textChangeHandler = (i) => {
setEnteredText(i.target.value);
//console.log(i.target.value);
};
const submitHandler = (event) => {
event.preventDefault();
const x = enteredText;
console.log(x);
setEnteredText("");
};
return (
<div className="App">
<h1>Get user input</h1>
<form onSubmit={submitHandler}>
<input
placeholder="type something"
type="text"
value={enteredText}
onChange={textChangeHandler}
/>
<button type="submit" >
Submit
</button>
</form>
<p>You just typed: {x}</p> // This is wrong. x is out of scope. But i'm not sure how to write this line.
</div>
);
}