I have a prop SubmissionComponent and need to assign a type to it.
It expects some sort of JSX – probably a button but more complicated structure possible.
So an example structure:
const SubmissionComponent = <p>hi</p>;
which is then called with
<Submitter
SubmissionComponent={SubmissionComponent} />
if in my Submitter component I define SubmissionComponent like this
SubmissionComponent: React.ReactNode;
and I make a
<SubmissionComponent/>
Then I get the error message where I place the component
JSX element type 'SubmissionComponent' does not have any construct or call signatures.
so ok, how about I change it to
SubmissionComponent: React.FunctionComponent;
Then I do not get any error in my code where I have placed the <SubmissionComponent/>
but I do get an error in my code where I do
<Submitter
SubmissionComponent={SubmissionComponent} />
that error being
Type 'Element' is not assignable to type 'FunctionComponent<{}>'.
Type 'Element' provides no match for the signature '(props: { children?: ReactNode; }, context?: any): ReactElement<any, any>'.
That implies to me that the type should be ReactElement, if I try
SubmissionComponent: React.ReactElement;
Then again I get the error
JSX element type 'SubmissionComponent' does not have any construct or call signatures.
if I try
SubmissionComponent: React.ReactElement<any, any>;
I also get the same error
React version is 17.0.2, typescript 4.6.3
2
Answers
const SubmissionComponent = <p>hi</p>;
the type of the const is "JSX.Element"if u make it a function, then u could use it like a "FunctionComponent" and assign it to "React.ReactNode"
The type of
SubmissionComponent
isJSX.Element
and you should use it in yourSubmitter
component with curly braces:{SubmissionComponent}
.Example:
Playground