Skip to content

Instantly share code, notes, and snippets.

@RileySeaburg
Last active July 17, 2021 20:51
Show Gist options
  • Save RileySeaburg/b33dd230d9d98b716ed66effd7a53710 to your computer and use it in GitHub Desktop.
Save RileySeaburg/b33dd230d9d98b716ed66effd7a53710 to your computer and use it in GitHub Desktop.
React Forms Input with Shopify Polaris & Typescript
import React, { ReactElement, useState, useCallback } from 'react'
import { TextField, FormLayout, Form } from '@shopify/polaris';
export default function ButtonForm(): ReactElement {
const [buttonText, setbuttonText] = useState('Button text');
const handleSubmit = (e: React.SyntheticEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(buttonText);
};
const handleChange = useCallback((newButtonText) => setbuttonText(newButtonText), []);
console.log(buttonText)
return (
<Form onSubmit={handleSubmit}>
<FormLayout >
<TextField
id="ButtonText"
label="Button Text"
onChange={handleChange}
value={buttonText}
/>
</FormLayout>
</Form>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment