Skip to content

Instantly share code, notes, and snippets.

@sawyerh
Last active June 27, 2021 18:14
Show Gist options
  • Save sawyerh/5633867d33d2f8266c2009f01798782b to your computer and use it in GitHub Desktop.
Save sawyerh/5633867d33d2f8266c2009f01798782b to your computer and use it in GitHub Desktop.
Page - Routing using state machines
import { getNextPathname, goTo } from "router";
import { updateApplication } from "api";
function IncomePage() {
// This is within the page for example purposes, but
// could be abstracted for a multi-page form.
const handleFormSubmit = (event) => {
event.preventDefault();
const formData = new FormData(event.target);
updateApplication(formData).then(() => {
const context = {
has_job_income: formData.get("has_job_income") === "Yes",
};
const nextPathname = getNextPathname("CONTINUE", context);
goTo(nextPathname);
});
};
return (
<form onSubmit={handleFormSubmit}>
<label>
<input name="has_job_income" type="checkbox" value="Yes" />
I have income from a job in 2021
</label>
</form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment