Skip to content

Commit 3a05e89

Browse files
committed
Update componentMapper page
1 parent daae740 commit 3a05e89

1 file changed

Lines changed: 42 additions & 15 deletions

File tree

packages/react-renderer-demo/src/app/pages/renderer/component-mapping.md

Lines changed: 42 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,16 @@ import ListOfContents from '../../src/helpers/list-of-contents';
77
<Grid container item>
88
<Grid item xs={12} md={10}>
99

10-
# Introduction
10+
# ComponentMapper
1111

1212
In order to successfully render a form via FormRenderer you need to assign component mappers. Component mapper is an object of React components,
1313
where key is a component identifier and value is the Component. The identifiers must be equivalent to `componentTypes` in your schema.
1414

15-
## FormTemplate
15+
## Creating componentMapper
1616

17-
TODO
18-
19-
## ComponentMapper
20-
Component mapper defines form inputs which can mutate the form state.
21-
22-
# Creating FormTemplate
23-
24-
25-
# Creating componentMapper
26-
27-
Form fields mapper defines components that are rendered from input schema. Each component in mapper must have an unique key,
28-
which corresponds to `componentType` in input schema. Keys names can be chosen but there are some predefined constants
29-
which cover most common component types. Predefined components are also automatically enhanced and connected to the form state.
17+
Component mapper defines components that are rendered from input schema. Each component in mapper must have an unique key,
18+
which corresponds to `componentType` in the schema. Keys names can be chosen but there are some predefined constants
19+
which cover most common component types.
3020

3121
```jsx
3222
import { componentTypes } from '@data-driven-forms/react-form-renderer';
@@ -48,6 +38,43 @@ const componentTypes = {
4838
}
4939
```
5040

41+
You have two options how to connect your component to the form state.
42+
43+
### useFieldApi
44+
45+
First, you can use `useFieldApi` hook.
46+
47+
This hook needs `name`, in case of special input types which are using checked as the input value (checbkoxes, switches) you have to assign `type: checkbox`. The hook will return all field props, including input and meta. [TODO: LINK TO WHAT IS INPUT AND META]
48+
49+
```jsx
50+
import { useFieldApi } from '@data-driven-forms/react-form-renderer';
51+
52+
...
53+
54+
const { input, isDisabled, label, helperText, description, meta } = useFieldApi(props);
55+
```
56+
57+
### FieldProvider
58+
59+
Or you can import `FieldProvider` component from Data Driven Forms. This component needs to obtain `render` or `component` prop.
60+
61+
62+
```jsx
63+
import { FieldProvider } from '@data-driven-forms/react-form-renderer'
64+
65+
<FielProvider component={TextField}>
66+
67+
// or
68+
69+
<FielProvider render={({input, meta, ...props}) => <TextField {...props} input={input} meta={meta}>}>
70+
```
71+
72+
## Example
73+
74+
Below, you can see an basic implementation of custom component mapper:
75+
<br />
76+
77+
5178
<RawComponent source="component-mapper/form-fields-mapper" />
5279
</Grid>
5380
<Grid item xs={false} md={2}>

0 commit comments

Comments
 (0)