|
1 |
| -This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app). |
2 | 1 | # JSON Forms React seed App
|
3 |
| -This seed demonstrates how to use [JSON Forms](https://jsonforms.io) with React in order to render a simple form for displaying a task entity. It showcases both the redux variant and the React standalone component (without redux). |
4 |
| - |
5 |
| -It is based on create-react-app and only contains minor modifications. |
6 | 2 |
|
7 |
| - * Execute `npm ci` to install the prerequisites. If you want to have the latest released versions use `npm install`. |
8 |
| - * Execute `npm start` to start the application. |
9 |
| - |
10 |
| - Browse to http://localhost:3000 to see the application in action. |
| 3 | +This seed demonstrates how to use [JSON Forms](https://jsonforms.io) with React in order to render a simple form for displaying a task entity. |
11 | 4 |
|
12 |
| -## File Structure |
13 |
| -Let's briefly have a look at the most important files: |
14 |
| -* `src/schema.json` contains the JSON schema (also referred to as 'data schema') |
15 |
| -* `src/uischema.json` contains the UI schema |
16 |
| -* `src/index.js` is the entry point of the application and sets up the redux store that contains the data, the JSON and the UI schema necessary for JSON Forms. |
17 |
| -* `src/App.js` is the main React component and makes use of the core JSON Forms component or the React standalone component in order to render a form. |
18 |
| - |
19 |
| -The [data schema](https://github.com/eclipsesource/jsonforms-react-seed/blob/master/src/schema.json) defines the structure of a Task: it contains attributes such as title, description, due date and so on. |
20 |
| - |
21 |
| -The [corresponding UI schema](https://github.com/eclipsesource/jsonforms-react-seed/blob/master/src/uischema.json) specifies controls for each property and puts them into a vertical layout that in turn contains two horizontal layouts. |
22 |
| - |
23 |
| -Both the data schema and the UI schema are imported within `index.js` and are used to set up a redux store. We make use of a helper function exported by JSON Forms which expects the initial state. If you already have an existing redux store, you'll need to import the jsonforms reducer and add it to your store. Please refer to [the tutorial](https://jsonforms.io/docs/tutorial) for how to do this. |
| 5 | +It is based on `create-react-app` and only contains minor modifications. |
24 | 6 |
|
25 |
| -## Setting up the store |
| 7 | +- Execute `npm ci` to install the prerequisites. If you want to have the latest released versions use `npm install`. |
| 8 | +- Execute `npm start` to start the application. |
26 | 9 |
|
27 |
| -```js |
28 |
| -const store = createStore( |
29 |
| - jsonformsReducer(), |
30 |
| - { |
31 |
| - jsonforms: { |
32 |
| - common: { |
33 |
| - data, |
34 |
| - schema, |
35 |
| - uischema |
36 |
| - }, |
37 |
| - renderers: JsonForms.renderers, |
38 |
| - cells: JsonForms.cells |
39 |
| - }, |
40 |
| - }, |
41 |
| - applyMiddleware(thunk) |
42 |
| -); |
| 10 | +Browse to http://localhost:3000 to see the application in action. |
43 | 11 |
|
44 |
| -// initialize store |
45 |
| -store.dispatch({ |
46 |
| - type: Actions.INIT, |
47 |
| - data, |
48 |
| - schema, |
49 |
| - uischema, |
50 |
| -}); |
| 12 | +## File Structure |
51 | 13 |
|
52 |
| -// trigger initial validation |
53 |
| -store.dispatch(Actions.validate()); |
54 |
| -``` |
| 14 | +Let's briefly have a look at the most important files: |
55 | 15 |
|
56 |
| -We then use the `Provider` component provided by `react-redux` to provide the store to the JSON Forms redux component and all its children. |
| 16 | +- `src/schema.json` contains the JSON schema (also referred to as 'data schema') |
| 17 | +- `src/uischema.json` contains the UI schema |
| 18 | +- `src/index.tsx` is the entry point of the application. We also customize the Material UI theme to give each control more space. |
| 19 | +- `src/App.tsx` is the main app component and makes use of the `JsonForms` component in order to render a form. |
57 | 20 |
|
58 |
| -```js |
59 |
| -<Provider store={store}> |
60 |
| - <JsonFormsReduxContext> |
61 |
| - <JsonFormsDispatch /> |
62 |
| - </JsonFormsReduxContext> |
63 |
| -</Provider> |
64 |
| -``` |
| 21 | +The [data schema](src/schema.json) defines the structure of a Task: it contains attributes such as title, description, due date and so on. |
65 | 22 |
|
66 |
| -## Rendering our form |
67 |
| -The `App` component is responsible for rendering our actual forms. |
| 23 | +The [corresponding UI schema](src/uischema.json) specifies controls for each property and puts them into a vertical layout that in turn contains two horizontal layouts. |
68 | 24 |
|
69 |
| -The redux form is rendered by importing and using `DispatchRenderer` from `@jsonforms/core`. `DispatchRenderer` expects `schema` and `uischema` props which define the form to be rendered but if those are omitted, they will be pulled from the store which was provided via `Provider` previously. |
| 25 | +## Rendering JSON Forms |
70 | 26 |
|
71 |
| -The standalone form is rendered by importing and using the `JsonForms` component and directly handing over the `schema`, `uischema`, `data`, `renderer` and `cell` props. We listen to changes in the form via the `onChange` callback . |
| 27 | +JSON Forms is rendered by importing and using the `JsonForms` component and directly handing over the `schema`, `uischema`, `data`, `renderer` and `cell` props. We listen to changes in the form via the `onChange` callback. |
72 | 28 |
|
73 | 29 | ## Custom renderers
|
| 30 | + |
74 | 31 | Please see [our corresponding tutorial](https://jsonforms.io/docs/tutorial) on how to add custom renderers.
|
0 commit comments