I am using the ES6 Class API for React (using TypeScript) and want to display a subtyped type class React.Componentusing ReactDOM.render().
The following code works:
class MyComponentProps {
someMember: string;
}
class MyComponent extends React.Component<MyComponentProps, {}> {
constructor(initialProps: MyComponentProps) {
super(initialProps);
}
}
let rootNode = document.getElementById('root');
ReactDOM.render(
<MyComponent someMember="abcdef" />,
rootNode
)
Now, given the explicit spelling of the constructor in react.d.ts, I would suggest that I can pass an instance of the MyCustomProps object that fills in the initial properties (as is done in the above code). But how to render a component directly without JSX / TSX syntax?
The following does not work:
ReactDOM.render(new MyComponent(new MyComponentProps()), rootNode);
I know that I can just use JSX syntax as a workaround, but since my object is MyCustomPropsquite large, I don't want to repeat every member of the object MyCustomProps.