Skip to content

Commit fa128f5

Browse files
committed
Some minor changes for v1, Added docs in the
readme
1 parent ab60cbc commit fa128f5

5 files changed

Lines changed: 125 additions & 9 deletions

File tree

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"cSpell.words": [
3+
"fetchforms"
4+
]
5+
}

README.md

Lines changed: 114 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,115 @@
1-
# Fetch Forms for react
2-
### Fetch Forms - build forms everywhere
1+
# Fetch Forms for React
32

4-
Docs go here
3+
### What is Fetch Forms?
4+
Fetch Forms is a headless forms solution and form builder designed to help developers build forms and connect data.
5+
6+
### Prerequisites
7+
1. [Configure a form](https://www.fetchforms.io/docs/configuring-a-form)
8+
2. [Create an API token](https://www.fetchforms.io/account/api-details)
9+
10+
## Documentation
11+
- [Examples](https://github.com/fetchforms/react-client/tree/main/src/examples)
12+
- [The Fetch Form object](https://www.fetchforms.io/docs/fetch-form-object)
13+
- [Storing forms in source code](https://www.fetchforms.io/docs/build-a-form)
14+
15+
### Install the client
16+
```sh
17+
npm install @fetchforms/react
18+
```
19+
```sh
20+
yarn add @fetchforms/react
21+
```
22+
23+
### Quick start
24+
Using the `<FetchForm />` component is the fastest way to see Fetch Forms in action. This component will handle client-side validation, data parsing, and saving to the cloud if your form has `cloudSave` set.
25+
26+
```jsx
27+
import { FetchForm, FetchFormsProvider } from "@fetchforms/react";
28+
29+
const MyFetchForm = () => {
30+
const onSubmit = async (values) => {
31+
console.log('values', values);
32+
};
33+
34+
return (
35+
<FetchFormsProvider permission="API_TOKEN">
36+
<FetchForm
37+
slug="FORM_SLUG"
38+
onSubmit={onSubmit}
39+
/>
40+
</FetchFormsProvider>
41+
);
42+
};
43+
```
44+
45+
### Using hooks
46+
The `useFetchForms` hook allows you to display your forms in more complex layouts. See the [hook form example](https://github.com/fetchforms/react-client/tree/main/src/examples/hookform) to see an implementation using Ant.Design form element.
47+
48+
```jsx
49+
import { useFetchForms, FetchFormsProvider } from "@fetchforms/react";
50+
51+
const CustomFormLayout = () => {
52+
const [fetchForm, loading, error] = useFetchForms('FORM_SLUG');
53+
54+
const onFinish = (values) => {
55+
console.log('values', values);
56+
};
57+
58+
return (
59+
<>
60+
{error && <div>Error: {error}</div>}
61+
{loading ? (
62+
<div>Loading...</div>
63+
) : (
64+
fetchForm && (
65+
<form
66+
name='HookForm'
67+
onSubmit={onFinish}
68+
>
69+
{fetchForm.formItems.map((item, i) => {
70+
if(item.fieldType === 'select') {
71+
return (
72+
<div key={item.fieldHtml.id}>
73+
<label for={item.fieldHtml.name}>{item.label}</label>
74+
<select {...item.fieldHtml}>
75+
{item.options.map((opt) => (
76+
<option value={opt.value} key={opt.value}>{opt.label}</option>
77+
))}
78+
</select>
79+
</div>
80+
);
81+
} else if (item.fieldType === 'checkbox') {
82+
return (
83+
<div key={item.fieldHtml.id}>
84+
<input {...item.fieldHtml} />
85+
<label for={item.fieldHtml.name}>{item.label}</label>
86+
</div>
87+
);
88+
{/* ...other field types */}
89+
} else {
90+
return (
91+
<div key={item.fieldHtml.id}>
92+
<input {...item.fieldHtml} />
93+
<label for={item.fieldHtml.name}>{item.label}</label>
94+
</div>
95+
);
96+
}
97+
})}
98+
<button type='submit'>
99+
{fetchForm.submitText}
100+
</button>
101+
</form>
102+
)
103+
)}
104+
</>
105+
)
106+
}
107+
108+
const App = () => {
109+
return (
110+
<FetchFormsProvider permission="API_TOKEN">
111+
<CustomFormLayout />
112+
</FetchFormsProvider>
113+
);
114+
}
115+
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fetchforms/react",
3-
"version": "0.1.10",
3+
"version": "1.0.0",
44
"description": "The React client SDK for Fetch Forms",
55
"author": "lukefrogger",
66
"license": "MIT",

src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import './App.css';
22
import { BrowserRouter, Routes, Route } from 'react-router-dom';
3-
import FullyManaged from './examples/FullyManaged';
4-
import HookParent from './examples/hookform/Parent';
3+
import ManagedForm from './examples/ManagedForm';
4+
import HookParent from './examples/hookForm/Parent';
55
import Layout from './examples/components/Layout';
66

77
function App() {
88
return (
99
<BrowserRouter>
1010
<Routes>
1111
<Route path='/' element={<Layout />}>
12-
<Route index element={<FullyManaged />} />
12+
<Route index element={<ManagedForm />} />
1313
<Route path='hookForm' element={<HookParent />} />
1414
</Route>
1515
</Routes>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { FetchForm, FetchFormsProvider } from '../lib/index';
33

4-
const FullyManaged = () => {
4+
const ManagedForm = () => {
55
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
66

77
const onSubmit = async (values) => {
@@ -29,4 +29,4 @@ const FullyManaged = () => {
2929
);
3030
};
3131

32-
export default FullyManaged;
32+
export default ManagedForm;

0 commit comments

Comments
 (0)