I have a form which takes name, age and gender as user input. When the submit button is clicked I want to transfer the state of the form to App.js where I can add the state to the array with users. How can I transfer the state from Form.js to App.js?
//Form.js
export const Form = ({ onClick }) => {
const [form, setForm] = useState({
name: "william",
age: 31,
gender: "male",
});
return <div><input type="submit" onClick={onClick}/></div>;
};
//App.js
export const App = () => {
const [users, setUsers] = useState({
name: "Anna",
age: 24,
gender: "female",
});
function addUser(e) {
e.preventDefault();
}
return (
<div>
<Form onClick={addUser} />
</div>
);
};