0

I want to write a function, which renders react component, passed as argument to that function. I want to handle both Component and StatelessComponent types. This is how I do that:

function renderComponent(component: React.ComponentClass<any> | React.StatelessComponent<any>) {
    return <component />;
}

I got compilation error:

error TS2604: JSX element type 'component' does not have any construct or call signatures.

What am I doing wrong?

1 Answer 1

1

In your example your renderComponent function is getting an instance of a Component and not a class/ctor.
It should be:

function renderComponent(componentClass: { new (): React.ComponentClass<any> | React.StatelessComponent<any> }) {
    return <componentClass />;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.