I have a definition object where depending on the ‘type’ of each form, I render a specific component. For example:
const definition =
{
name: "test",
id: 1,
form: [
{type: "text"},
{type: "checkbox"},
{type: "radio"}]
};
So to access the form types Im just doing a simple map:
const definitionTypes = definitions.form.map ( form => form.type )
I now have an array of all the form type’s entries stored on definitionTypes and I have three components that needs to render depending on which keyword is in that definitionTypes array. So for the “text” I have a component that Im importing called <DefinitionText /> , etc.
Where Im am experiencing problems is figuring out a solution to return multiple components based on the types that are in the definitionTypes array. The end goal would be for these 3 components to render from that array:
// if definitionTypes includes "text" then render...
<DefinitionText />
// also if definitionTypes includes "checkbox" then render...
<DefinitionCheckbox />
// also if definitionTypes includes "radio" then render...
<DefinitionRadio />
I’ve tried using an if/else statement to push each component to a results variable then rendering that but the results variable sends back an error. Any help in getting multiple components to render based off conditions would be a huge help!