Last active
July 23, 2018 01:08
-
-
Save JonAbrams/2bd80a23bbf81b880f7eaace3f2936a4 to your computer and use it in GitHub Desktop.
Revisions
-
JonAbrams revised this gist
Jul 23, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -38,7 +38,7 @@ export const PizzaForm = ({ space }) => ( {/* ... some input elements */} <p className="error">{space.errorMsg}</p> {space.pizza && <p>You’ve been given: {space.pizza}</p>} <button disabled={space.saving} type="submit">Get Pizza</button> <button disabled={space.saving} type="button" onClick={space(handleReset)}>Reset</button> </form> ); -
JonAbrams revised this gist
Jul 23, 2018 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -21,8 +21,12 @@ const handleSubmit = async ({ space, merge }, event) => { }); }; /* handleReset is another custom action. This one erases all properties on the space, replacing them with only the specified ones. */ const handleReset = ({ replace }) => { replace({ name: '', pizzaLover: false -
JonAbrams revised this gist
Jul 23, 2018 . 1 changed file with 6 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,9 +1,11 @@ import { fetchPizza } from '../apiCalls'; /* handleSubmit is a custom action. The first parameter is provided by SpaceAce. The remaining parameters are passed-through which in this case consists of React's event object */ const handleSubmit = async ({ space, merge }, event) => { event.preventDefault(); -
JonAbrams revised this gist
Jul 23, 2018 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,9 @@ import { fetchPizza } from '../apiCalls'; // handleSubmit is a custom action // The first parameter is provided by SpaceAce // The remaining parameters are passed-through // which in this case consists of React's event object const handleSubmit = async ({ space, merge }, event) => { event.preventDefault(); -
JonAbrams revised this gist
Jul 22, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,7 +23,7 @@ const handleReset = ({ replace }) => { }); }; export const PizzaForm = ({ space }) => ( <form onSubmit={space(handleSubmit)}> {/* ... some input elements */} <p className="error">{space.errorMsg}</p> -
JonAbrams renamed this gist
Jul 22, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
JonAbrams renamed this gist
Jul 22, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
JonAbrams created this gist
Jul 22, 2018 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import { fetchPizza } from '../apiCalls'; const handleSubmit = async ({ space, merge }, event) => { event.preventDefault(); // merge does a shallow merge, allowing the assignment of multiple properties at once merge({ saving: true }); // updates space immediately, triggers re-render const { data, error } = await fetchPizza({ name: space.name }); if (error) return merge({ error: errorMsg, saving: false }); merge({ saving: false, pizza: data.pizza // 'Pepperoni', hopefully }); }; const handleReset = ({ replace }) => { // Replace erases all properties, replacing them with only the given ones replace({ name: '', pizzaLover: false }); }; export const MyForm = ({ space }) => ( <form onSubmit={space(handleSubmit)}> {/* ... some input elements */} <p className="error">{space.errorMsg}</p> {space.pizza && <p>You’ve been given: {space.pizza}</p>} <button disabled={space.saving} type="submit">Submit</button> <button disabled={space.saving} type="button" onClick={space(handleReset)}>Reset</button> </form> );