Answer the question
In order to leave comments, you need to log in
How to create a recursive component correctly?
I have view data:
{
name: "Name",
required: true,
type: "object",
properties: [
{
name: "Name2",
required: false,
type: "object",
properties: [
{
name: "Name3",
required: false,
type: "text"
},
{
name: "Name4",
required: false,
type: "text"
}
]
},
{
name: "Name5",
required: false,
type: "text"
}
]
}
import React, { Component } from 'react';
export default class PropertiesParser extends Component {
render() {
let propers = this.props.properties;
if (propers) {
switch (propers.type) {
case "text":
return (
<div className="row">
<div className="col-md-2">
{propers.name}
</div>
<div className="col-md-10">
<input
type="text"
name={propers.name}
required={propers.required}
value="" />
</div>
</div>
);
break;
case "object":
return (<div>{propers.properties.map(property =>
<PropertiesParser key={propers.Name + Math.random()} properties={property} />
)}</div>);
break;
}
}
return (
<div>
</div>
);
}
}
Uncaught RangeError: Maximum call stack size exceeded
{name: "Name", required: true, properties: Array(2), type: "object"}
{name: "Name2", required: true, type: "object"}
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question