Can I create components from Javascript data?

What I'd like to do is dynamically create/remove components based on data in an array. For instance, let's say I have an array ['First', 'Second', 'Third'], I want to be able to generate three components that have the values First, Second, and Third. Think of a list Item. Like you could map through the array and for each value in the array, create a component with their value set to that value. Is this something that is possible in Retool? Or do we have to make use of React for that?

2 Likes

@Kayode

Hey there :wave: Thanks for reaching out! This is not currently possible in Retool so I will move this over to our Feature Requests :slightly_smiling_face:

+1

Hi @fabianmu Thanks for your plus one here!

While this hasn't shipped yet, I wanted to at list out the known workarounds, aside from using your own React code:

  1. [Native Retool components] You can use a listView with a dynamic length to "create" new items in the list. In this case, you'd already have the components set up, but the amount of each component would be dynamic:
  2. [JSON Schema Form + non-native Retool components] You can dynamically update the JSON that the JSON Schema form is referencing in order to "create" new form inputs

In both cases, you are not generating new components (we'll still keep track of that feature request). Instead, you're using dynamic inputs to decide how many components will be shown.

1 Like

@Tess I am very interested in your comment (2):
You can dynamically update the JSON that the JSON Schema form is referencing in order to "create" new form inputs

But the image you linked says access denied. Can you direct me to info about how to dynamically update the JSON that the JSON Schema form is referencing?

Thanks for flagging! I'm attaching an example app that you can import to see what I mean.

In the app, my json schema form is populated by temporary state. When I update the temporary state with new json schema form inputs, the component re-renders with newly "created" components

Let me know what questions come up!
create-20components-202.json

I wish I could use a module with the list view component workaround.

Hi @johnwp modules in listviews is a feature request that we're tracking internally. I'll let our team know you're also looking for this feature, and I'll post back on this thread if we're able to ship this