Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fetchforms/fetch-forms-react

The react client for Fetch Forms
https://github.com/fetchforms/fetch-forms-react

form form-builder form-validation forms react

Last synced: about 1 month ago
JSON representation

The react client for Fetch Forms

Awesome Lists containing this project

README

        

# Fetch Forms for React

### What is Fetch Forms?
Fetch Forms is a headless forms builder designed to help developers build forms and connect data.

## Documentation
- [Full code examples](https://github.com/fetchforms/react-example-app)
- [Doc Overview](https://www.fetchforms.io/docs/overview)
- [The Fetch Form object](https://www.fetchforms.io/docs/fetch-form-object)
- [Storing forms in source code](www.fetchforms.io/docs/source-code-forms)

### Add the package to your app
```sh
npm install @fetchforms/react
```
```sh
yarn add @fetchforms/react
```

### Quick start
Using the `` 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.

```jsx
import { FetchForm } from "@fetchforms/react";

const MyFetchForm = () => {
const onSubmit = async (values) => {
console.log('values', values);
};
const onLoad = async (values) => {
console.log('values', values);
};

return (

);
};
```

### Using hooks
The `useFetchForms` hook allows you to display your forms in more complex layouts. See the [custom form example](https://github.com/fetchforms/react-example-app/tree/main/src/examples) to see an implementation using Ant.Design form element.

```jsx
import { useFetchForms } from "@fetchforms/react";

const CustomFormLayout = () => {
const [fetchForm, loading, error] = useFetchForms('FORM_SLUG');

const onFinish = (values) => {
console.log('values', values);
// To show an error on the form, return a message as a string.
};

return (
<>
{error &&

Error: {error}
}
{loading ? (
Loading...

) : (
fetchForm && (

{fetchForm.formItems.map((item, i) => {
if(item.fieldType === 'select') {
return (

{item.label}

{item.options.map((opt) => (
{opt.label}
))}


);
} else if (item.fieldType === 'checkbox') {
return (


{item.label}

);
{/* ...other field types */}
} else {
return (


{item.label}

);
}
})}

{fetchForm.submitText}


)
)}
>
)
}
```