import React, { useState } from "react";
function App() {
const [fName, setfName] = useState("");
function changefName(event) {
setfName(event.target.value);
}
return (
<div className="container">
<h1>
Hello {fName}
</h1>
<form>
<input
name="fName"
placeholder="First Name"
onChange={changefName}
value={fName}
/>
<button>Submit</button>
</form>
</div>
);
}
What can happen if I don't declare value={fName}
in my input tag? I understand the difference between controlled and uncontrolled component from this post, but I don't understand the significance if I don't declare whether it is controlled or uncontrolled.
Full code here: https://codesandbox.io/s/changing-complex-state-forked-llfq2f?file=/src/components/App.jsx