Functional component do not have lifecycle hooks. So, here you just use the return statement or implicit return using parentheses ()
instead of curly brace {}
and return statement, which will render the component:
const CoolComponent = props => {
return (
<Bar
foo={true}
{...propz}
/>
)
}
The preceding example of code has issue with the props. See below for proper example.
Also, when you have the props with the value of true
, you can just simply use the props. Here's what I would use simply:
const CoolComponent = props => {
const { foo, ...rest } = props
return <Bar foo {...rest} />
}
Or,
const CoolComponent = ({foo, ...rest}) => {
return <Bar foo {...rest} />
}
Or even one line with your example:
const CoolComponent = ({foo, ...rest}) => <Bar foo {...rest} />
Single line statement will only be valid when you don't have multi line of code.
Implicit return with multiline of code:
const CoolComponent = ({foo, ...rest}) => (
<div>
<Bar foo {...rest} />
</div>
)
You may also read my another post explaining about implicit and explicit return.