# Accessing jsonforms schema from a custom renderer

**URL:** <https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455>\
**Category:** General\
**Created:** [October 22, 2021, 6:52pm UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455 "2021-10-22T18:52:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![eshadatta](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eshadatta/32/194_2.png) [@eshadatta](https://jsonforms.discourse.group/u/eshadatta)\
**Post date:** [October 22, 2021, 6:52pm UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/1 "2021-10-22T18:52:16Z")

</div>

Hello,

Thanks for the good overview on json forms. I have a question about using the updateCore dispatch method. If I wanted to bulk update a number of fields and wanted to use the updateCore method, I am having a hard time passing the jsonforms schema and uischema. I get an error when I do so. Here are the relevant code bits:

In my custom renderer, I inject the jsonforms object in the setup method:

```auto
setup(props: RendererProps<ControlElement>) {
const jsonforms = inject<JsonFormsSubStates>('jsonforms');
const s = jsonforms?.core?.schema;
const ui = jsonforms?.core?.uischema;
return { jsonforms, s, ui }

```

In my update method, I try to access these variables and would like to update a number of fields, so try to use `updateCore`:

```auto
    getData(id: string) {
      const rootData = this.jsonforms?.core?.data;
          let updatedData = rootData;
          updatedData = set(
            'addresses.geonames_city.city',
            data.asciiName,
            updatedData
          );
          if (this.dispatch) {
            this.dispatch(
              Actions.updateCore(
                updatedData
                this.s,
                this.ui
              )
            );
          }
        });
      });
    }

```

The getData method will be getting a data response from an api and then populating several fields with the response from there. Seeing how to use `update` was very helpful but I’d like to also see how to use `updateCore`? Right now, when I try this, I get a typescript error with the following message: `[!] (plugin rpt2) Error: /Users/eshadatta/jsonforms-vuetify-renderers/vue2-vuetify/src/controls/GeoNamesLookupRenderer.vue?rollup-plugin-vue=script.ts(96,17): semantic error TS2345: Argument of type 'JsonSchema4 | JsonSchema7 | undefined' is not assignable to parameter of type 'JsonSchema'. Type 'undefined' is not assignable to type 'JsonSchema'.`. If I could know how to pass the json forms schema to the custom renderer and use it for the updateCore method, that would be super helpful.

Thanks so much.

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [October 25, 2021, 7:18am UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/2 "2021-10-25T07:18:22Z")

</div>

Hi @eshadatta!

Thanks for the very detailed request, that is certainly helpful 😉

Your code looks fine. It seems it’s just a Typescript problem. The `updateCore` method expects type `JsonSchema` while the `jsonforms?.core?.schema;` will result in in type `JsonSchema | undefined`.

At this point of time we can be sure that there is a `JsonSchema` as without one JSON Forms will not even render. So you can just cast the schema, i.e. `this.dispatch(Actions.updateCore(updatedData, (this.s as JsonSchema), this.ui));`. Alternatively you can also just type the schema as `any` in `setup` which lifts all type restrictions.

Whenever you encounter a blocking Typescript error you can try to go ahead with casting to `any` and check whether that works. Of course you might mask a bug this way, so I would recommend going over all these cases in batch at some point to see whether there is a better way.

---

<div class="post-metadata">

**Author:** ![eshadatta](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/eshadatta/32/194_2.png) [@eshadatta](https://jsonforms.discourse.group/u/eshadatta)\
**Post date:** [October 25, 2021, 1:20pm UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/3 "2021-10-25T13:20:28Z")

</div>

Fantastic, thanks so much for the quick and detailed response!

---

<div class="post-metadata">

**Author:** ![gyrevik](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/gyrevik/32/237_2.png) [@gyrevik](https://jsonforms.discourse.group/u/gyrevik)\
**Post date:** [January 27, 2022, 12:11am UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/4 "2022-01-27T00:11:01Z")

</div>

In the seed app, if I want to set the InputLabel text from schema.json where I added “title”: “RatingXYZ” to the object the rating key refers to – would the above discussion be the approach for getting that data into the custom control?

Never mind. I found it. Just had to add schema to RatingControlProps.

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 27, 2022, 11:27am UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/5 "2022-01-27T11:27:23Z")

</div>

Hi @gyrevik, just to be sure: You’re talking about the JSON Forms React seed right? The previous discussion here resolved about the JSON Forms Vue2 Vuetify renderers, so the code discussed here is not applicable.

---

<div class="post-metadata">

**Author:** ![gyrevik](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/gyrevik/32/237_2.png) [@gyrevik](https://jsonforms.discourse.group/u/gyrevik)\
**Post date:** [January 27, 2022, 2:49pm UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/6 "2022-01-27T14:49:13Z")

</div>

I was talking about the JSON Forms React seed. I realized that I just had to add schema in RatingControl/RatingControlProps.

const RatingControl = ({ data, handleChange, path, schema }: RatingControlProps) =\> {

I’m good now. Thank you!

---

<div class="post-metadata">

**Author:** ![sdirix](https://yyz2.discourse-cdn.com/free1/user_avatar/jsonforms.discourse.group/sdirix/32/1073_2.png) [@sdirix](https://jsonforms.discourse.group/u/sdirix)\
**Post date:** [January 27, 2022, 3:19pm UTC](https://jsonforms.discourse.group/t/accessing-jsonforms-schema-from-a-custom-renderer/455/7 "2022-01-27T15:19:05Z")

</div>

Yes perfect 😉 FYI should you also ever need to access the form-wide storage of configuration, data, etc. then you can use `const ctx = useJsonForms()`.
