Reputation: 1481
How can I do something like this correctly in React?
import Bar from './Bar.jsx'
const Foo = ({ icon = <Bar />}) => {
// ...
}
export default Foo
Right now using icon = <Bar />
will simple give parsing error.
Upvotes: 3
Views: 784
Reputation: 629
Don't include the <>
's, just assign it however it's imported (so Bar in this case).
You'll need to make the icon prop have a capital I, then you can use <Icon />
to call any component passed to it.
If Bar has any props, add them to Icon and they'll be passed through to Bar.
import Bar from './Bar.jsx'
const Foo = ({ Icon = Bar }) => {
return (
<Icon />
)
}
export default Foo
Upvotes: 1