Skip to content

Commit a556489

Browse files
committed
Update custom components page
1 parent 5b480b8 commit a556489

2 files changed

Lines changed: 60 additions & 32 deletions

File tree

packages/react-renderer-demo/src/app/pages/renderer/field-provider.md

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,47 +9,27 @@ import ListOfContents from '../../src/helpers/list-of-contents';
99
<Grid container item>
1010
<Grid item xs={12} md={10}>
1111

12-
# Field Provider
13-
14-
## Custom components
12+
# Custom components
1513

1614
React form renderer is using [react-final-form](https://github.com/final-form/react-final-form) for form state management.
1715
Most of its features are not directly available for consistency and performance reasons. If you want to create any custom
18-
components, you can access these features via `FieldProvider` prop.
16+
components, you can access these features via `FieldProvider` component or `useFieldApi` hook.
1917

20-
FieldProvider is a wrapper component around standard
21-
[react-final-form Field component](https://final-form.org/docs/react-final-form/api/Field)
22-
which adds additional methods that will help you to control your form state.
18+
`FieldProvider` is a wrapper using `useFieldApi` to get the access to the form state.
2319

24-
# Accessing FieldProvider
20+
`useFieldApi` is a wrapper around [React Final Form useField hook](https://final-form.org/docs/react-final-form/api/useField).
2521

26-
To use Fieldprovider, you first need to register a component to your component mapper.
2722
You can read more about that in <RouterNav href="/renderer/component-mapping"><Link href="/renderer/component-mapping">Component mapping</Link></RouterNav>.
2823

29-
Each component will receive FieldProvider as a prop. Be aware that pre-defined component types are
30-
automatically wrapped in FieldProvider. This is done to make it easier to create component mappers for
31-
standard form components. List of standard components is available <RouterNav href="/renderer/component-api"><Link href="/renderer/component-api">here</Link></RouterNav>.
32-
33-
# Using FieldProvider
34-
35-
## Register component
36-
37-
```jsx
38-
import NewComponent from './new-component'
39-
40-
const componentMapper = {
41-
'new-component': NewComponent
42-
}
43-
```
44-
4524
## Implementation of component
4625

4726
Next example shows simple input field with label and error message.
4827

4928
```jsx
5029
import React from 'react';
30+
import { FieldProvider } from '@data-driven-forms/react-form-renderer'
5131

52-
const NewComponent = ({ FieldProvider, formOptions, name, ...rest }) => (
32+
const NewComponent = ({ name, ...rest }) => (
5333
<div>
5434
<FieldProvider {...rest} name={name}>
5535
{({ input, meta, ...props }) => {
@@ -68,6 +48,18 @@ const NewComponent = ({ FieldProvider, formOptions, name, ...rest }) => (
6848
export default NewComponent
6949
```
7050

51+
## Register component
52+
53+
To be able to use your component in the schema, you first need to register the component in your component mapper.
54+
55+
```jsx
56+
import NewComponent from './new-component'
57+
58+
const componentMapper = {
59+
'new-component': NewComponent
60+
}
61+
```
62+
7163
# What are input and meta?
7264

7365
## Input
@@ -100,11 +92,23 @@ Meta is a object which contains meta information about field with given name. Th
10092
}
10193
```
10294

103-
# FormOptions
95+
# useFormApi - formOptions
10496

105-
In addition to FieldProvider, every component will also receive prop `formOptions`.
10697
This property contains a number of useful methods and attributes that will give you additional level of control
107-
and informations about the formState.
98+
and information about the formState.
99+
100+
You can access it from every component by using `useFormApi` hook.
101+
102+
```jsx
103+
import { useFormApi } from '@data-driven-forms/react-form-renderer';
104+
105+
const Component = (props) => {
106+
const formOptions = useFormApi();
107+
...
108+
}
109+
```
110+
111+
This hook returns object containing following information:
108112

109113
```jsx
110114
{
@@ -120,9 +124,29 @@ and informations about the formState.
120124
}
121125
```
122126

123-
# FormSpy provider
127+
# FormSpy
128+
129+
[FormSpy](https://final-form.org/docs/react-final-form/api/FormSpy) is exported via Data Driven Forms.
130+
131+
```jsx
132+
import { FormSpy } from '@data-driven-forms/react-form-renderer';
133+
```
134+
135+
# FieldArray
124136

125-
Every component also receives component `FormSpyProvider` as a prop. You can find more info <a href="https://final-form.org/docs/react-final-form/api/FormSpy" rel="noopener noreferrer" target="_blank">here!</a>
137+
[React Final Form Array](https://github.com/final-form/react-final-form-arrays) is exported via Data Driven Forms.
138+
139+
```jsx
140+
import { FieldArray } from '@data-driven-forms/react-form-renderer';
141+
```
142+
143+
# Form
144+
145+
For testing purposes, you can also import React Final Form's `Form` component.
146+
147+
```jsx
148+
import { Form } from '@data-driven-forms/react-form-renderer';
149+
```
126150

127151
</Grid>
128152
<Grid item xs={false} md={2}>

packages/react-renderer-demo/src/app/src/components/mdx/mdx-components.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ const MdxComponents = {
8787
/>
8888
</div>
8989
),
90-
link: ({ href, children }) => <Link href={href}>{children}</Link>,
90+
a: ({ href, children }) => (
91+
<Link href={href} rel="noopener noreferrer" target="_blank">
92+
{children}
93+
</Link>
94+
),
9195
h1: (props) => <Heading {...props} level={4} component="h1" />,
9296
h2: (props) => <Heading {...props} level={5} component="h2" />,
9397
h3: (props) => <Heading {...props} level={6} component="h3" />,

0 commit comments

Comments
 (0)