I want to create an object:
import React from "react";
import { Registration } from "../../";
const RouteObj = {
Registration: {
route: "/registration",
comp: <Registration />
}
};
export default RouteObj;
And then, in a second file call:
import React from 'react';
import RouteObj from ...
class Thing extends React.Component{
render() {
<RouteObj.Registration.comp />
}
}
When trying this, I get the error:
React.createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in.
Is it possible to render React components in this way?
Registration is already a tag (a component), that's why I guess you have to use curly brackets instead.
import React from 'react';
import RouteObj from ...
class Thing extends React.Component{
render() {
<div>
{RouteObj.Registration.comp}
</div>
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With