Skip to content

Commit 3af8f33

Browse files
LukasBollsdirix
andauthored
Apply suggestions from code review
Co-authored-by: Stefan Dirix <[email protected]>
1 parent 7654703 commit 3af8f33

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

content/docs/tutorial/dynamic-enum.mdx

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ This approach allows you to build flexible and interactive forms that adapt to u
1515
Imagine a form where users need to provide their location by selecting a country, a region and a city.
1616
The options for countries and regions are fetched from an API.
1717
The available regions depend on the selected country.
18-
To address those requirements, we'll create custom renderers for the country and region.
19-
The example is also implemented in the [react-seed](https://github.com/eclipsesource/jsonforms-react-seed) app.
18+
To address those requirements, we'll create custom renderers for country and region.
2019

2120
<WithRegionRenderer />
2221

@@ -26,7 +25,7 @@ The example is also implemented in the [react-seed](https://github.com/eclipseso
2625
To begin, let's introduce the corresponding JSON schema.
2726
We have created an object with properties for country, region, and city.
2827
In our example, the schema also includes a property `x-url`, which specifies the entry point of the corresponding API.
29-
Both `country` and `region` have a property `endpoint`, indicating the endpoint from which the data should be fetched.
28+
Both `country` and `region` have a property `x-endpoint`, indicating the endpoint from which the data should be fetched.
3029
Additionally, they have a field specifying which fields depend on the input.
3130
In the case of the `country` field, the `region` and `city` fields depend on it and will get reset, if the value of the `country` changes.
3231
The `city` field, in turn, is dependent on the `region` field.
@@ -84,7 +83,7 @@ const App = () =>{
8483

8584
### The Country Renderer
8685

87-
The core of the country renderer is a dropdown, we can reuse the MaterialEnumControl from the material-renderer set.
86+
The core of the country renderer is a dropdown, therefore we can reuse the MaterialEnumControl from the React Material renderer set.
8887
To reuse material renderers, the Unwrapped renderers must be used. (more information regarding reusing renderers can be seen [here](./custom-renderers#reusing-existing-controls))
8988

9089
```js
@@ -120,7 +119,7 @@ Changing the context's value will trigger a re-render of components that use it,
120119
#### Accessing Schema Data
121120

122121
The `endpoint` and `dependent` fields can be obtained from the schema object provided to the custom renderer via JSON Forms.
123-
Since these fields are not part of the standard JSON schema type in JSON Forms, we must add them to the schema´s interface and access them as follows:
122+
Since these fields are not part of the standard JSON schema type in JSON Forms, we must add them to the schema's interface and access them as follows:
124123

125124
```js
126125
type JsonSchemaWithDependenciesAndEndpoint = JsonSchema & {
@@ -142,7 +141,7 @@ export const Country = (
142141
#### The Country Renderer
143142

144143
The country renderer uses the `APIContext` to query the API and fetch the available options.
145-
We utilize the `useEffect` hook to reload new options, if API changes.
144+
We utilize the `useEffect` hook to initialize the options.
146145
While waiting for the API response, we set the available options to empty and display a loading spinner.
147146
In the `handleChange` function, we set the new selected value and reset all dependent fields;
148147
When changing the country, both the region and city will be reset to `undefined`.
@@ -169,11 +168,10 @@ export const Country = (
169168
const dependent: string[] = schema.dependent ? schema.dependent : [];
170169

171170
useEffect(() => {
172-
setOptions([]);
173171
api.get(endpoint).then((result) => {
174172
setOptions(result);
175173
});
176-
}, [api, endpoint]);
174+
}, []);
177175

178176
if (options.length === 0) {
179177
return <CircularProgress />;

0 commit comments

Comments
 (0)