Skip to content

Commit

Permalink
docs: add demo link into readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Thanga-Ganapathy committed Apr 23, 2023
1 parent 59f654a commit 0210e6e
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/gentle-pears-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@opentf/react-form': patch
---

Added demo link into the readme.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

> Build forms & manage their state in React.
## [View Demo](https://react-form.pages.dev/#demo)

## Features

- Simple APIs to use
Expand Down Expand Up @@ -55,9 +57,32 @@ export default function App() {
}}
>
<Field name="field1" />
<button type="submit">Submit</button>
</Form>
);
}
```

## Usage (TypeScript)

{/* Other fields... */}
```tsx
import { Form, Field } from '@opentf/react-form';

interface FormValues {
field1: string;
}

export default function App() {
const initialValues: FormValues = { field1: '' };

return (
<Form
initialValues={initialValues}
onSubmit={(values) => {
console.log(values);
}}
>
<Field name="field1" />
<button type="submit">Submit</button>
</Form>
);
Expand All @@ -66,7 +91,7 @@ export default function App() {

## Documentation

Please visit [https://react-form.pages.dev/](https://react-form.pages.dev/) for complete documentation.
Please visit [https://react-form.pages.dev/](https://react-form.pages.dev/) to get started.

## License

Expand Down
12 changes: 3 additions & 9 deletions apps/website/docs/API/useField.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,13 @@ The `hook` function returns an `object` containing a `field` object, an `error`
```jsx
import { useField } from '@opentf/react-form';

function MyCustomField1({ name }) {
const { field } = useField(name);

return <input {...field} />;
}

function MyCustomField2({ name }) {
const { field, error, setValue } = useField(name);
function MyCustomField({ name }) {
const { field, error } = useField(name);

return (
<>
<input
onChange={(e) => setValue(e.target.value)}
onChange={(e) => field.onChange(e.target.value)}
onBlur={field.onBlur}
value={field.value}
/>
Expand Down
2 changes: 1 addition & 1 deletion apps/website/src/examples/SelectField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function App() {
return (
<div className="App">
<Form
initialValues={{ location: { city: 'Chennai' } }}
initialValues={{ location: { city: 'Chennai' }, pets: [] }}
onSubmit={(values) => console.log(values)}
>
<div>
Expand Down
29 changes: 27 additions & 2 deletions packages/react-form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

> Build forms & manage their state in React.
## [View Demo](https://react-form.pages.dev/#demo)

## Features

- Simple APIs to use
Expand Down Expand Up @@ -55,9 +57,32 @@ export default function App() {
}}
>
<Field name="field1" />
<button type="submit">Submit</button>
</Form>
);
}
```

## Usage (TypeScript)

{/* Other fields... */}
```tsx
import { Form, Field } from '@opentf/react-form';

interface FormValues {
field1: string;
}

export default function App() {
const initialValues: FormValues = { field1: '' };

return (
<Form
initialValues={initialValues}
onSubmit={(values) => {
console.log(values);
}}
>
<Field name="field1" />
<button type="submit">Submit</button>
</Form>
);
Expand All @@ -66,7 +91,7 @@ export default function App() {

## Documentation

Please visit [https://react-form.pages.dev/](https://react-form.pages.dev/) for complete documentation.
Please visit [https://react-form.pages.dev/](https://react-form.pages.dev/) to get started.

## License

Expand Down

0 comments on commit 0210e6e

Please sign in to comment.