Last active
June 27, 2021 18:14
-
-
Save sawyerh/5633867d33d2f8266c2009f01798782b to your computer and use it in GitHub Desktop.
Page - Routing using state machines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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