Skip to content

Instantly share code, notes, and snippets.

@jamiehaywood
Last active November 22, 2020 23:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiehaywood/d8cf99a8b618a3a6117ae7c6afcf15ed to your computer and use it in GitHub Desktop.
Save jamiehaywood/d8cf99a8b618a3a6117ae7c6afcf15ed to your computer and use it in GitHub Desktop.
import React from "react";
import { useHistory } from "react-router-dom";
import { useForm } from "react-hook-form";
import { useGlobalState, GlobalStateInterface } from "./GlobalStateProvider";
const PageOne = () => {
const history = useHistory();
const { handleSubmit, register } = useForm();
const { setState } = useGlobalState();
const submitFunction = (data: Partial<GlobalStateInterface>) => {
setState((prev) => ({ ...prev, ...data }));
history.push("/two");
};
return (
<div>
<h1>PAGE ONE</h1>
<form onSubmit={handleSubmit(submitFunction)}>
<div>
<label htmlFor="firstname">First name:</label>
<input ref={register} type="text" id="firstname" name="firstname" />
</div>
<div>
<label htmlFor="lastname">Last name:</label>
<input ref={register} type="text" id="lastname" name="lastname" />
</div>
<div>
<label htmlFor="age">Age:</label>
<input ref={register} type="number" id="age" name="age" />
</div>
<button type="submit">Next Page</button>
</form>
</div>
);
};
export default PageOne;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment