I have a situation where I want to render a default component, UNLESS a different one is passed in an object.
{map(changes, item => {
const hasChanged = item.fromValue !== item.toValue;
const Component = item.Component;
return (
<div key={uuid.v4()} className="row">
<div className="col-md-6">
{Component ? (
<Component
key={uuid.v4()}
labelColor={hasChanged ? '#AB2912' : ''}
backgroundColor={hasChanged ? '#FFEE7E' : ''}
shouldBoldValue={hasChanged}
label={item.label}
cssClasses="preview-item-padding"
capitalize={false} />
) : (
<SimpleLabelText
key={uuid.v4()}
labelColor={hasChanged ? '#AB2912' : ''}
backgroundColor={hasChanged ? '#FFEE7E' : ''}
shouldBoldValue={hasChanged}
label={item.label}
text={item.toValue}
cssClasses="preview-item-padding"
capitalize={false} />
)}
</div>
</div>
);
})}
In that code above, I want to render SimpleLabelText unless the item object has a Component property. Component is a jsx tag created in a different file.
I don't think it matters, but here is the function that creates the tag in the other file (this is temporary, I'm going to add stuff to it later)
function getCustomComponent(text) {
return (
<SimpleLabelText
text='something'
/>
);
}
However, when I run this, the whole thing explodes and I get this error message;
Warning: React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: . Did you accidentally export a JSX literal instead of a component?
How can I properly render the jxg tag that is getting assigned to Component?