Skip to content

Instantly share code, notes, and snippets.

@intojs
Created February 21, 2021 20:18
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 intojs/392746f1fb6f405bb7c1277406dc576b to your computer and use it in GitHub Desktop.
Save intojs/392746f1fb6f405bb7c1277406dc576b to your computer and use it in GitHub Desktop.
const NewsletterForm = ({ newsletterOptions, onSubmit }) => {
const [model, dispatch] = useReducer(reducer, initialModel);
useEffect(() => {
dispatch(actions.setNewsletterOptions(newsletterOptions));
}, [newsletterOptions]);
const handleFieldChange = (change) => {
dispatch(actions.changeField(change));
};
const handleSubmit = () => {
const {
fields: { fullName, newsletter },
} = model;
onSubmit({ fullName: fullName.value, newsletter: newsletter.value });
};
return (
<View
model={model}
onFieldChange={handleFieldChange}
onSubmit={handleSubmit}
/>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment