Adrienne
Adrienne

Reputation: 2680

How do you pass a component into the attribute of a component in React?

I have SplitPane component class with attributes body and side. I also have a Table component class I'm trying to insert but I keep getting an error.

<SplitPane side='hi' body=<MyTable /> />

will return

JSXAttribute expected node to be of a type ["JSXElement","StringLiteral","JSXExpressionContainer"] but instead got "CallExpression"

Upvotes: 1

Views: 541

Answers (2)

Andrew Axton
Andrew Axton

Reputation: 1030

You need to wrap it in curly braces and remove the JSX. Just pretend it's a normal variable.

<SplitPane side='hi' body={MyTable} />

Upvotes: 2

Adrienne
Adrienne

Reputation: 2680

It should be <SplitPane side='hi' body={<MyTable />} />

Upvotes: 0

Related Questions