Saturday, 9 October 2021

React hooks: call component as function vs render as element

Say we have component:

let Component = (props)=><div>Hi</div>;

I have often come across code where someone calls a react component as function in render:

 const App = () => (
     <div> {Component()} </div>
 )

vs rendering it as element

 const App = () => (
     <div> <Component/> </div>
 )

In react hooks, which is recommended practice?


There is similar question but it is not specifically targeted at hooks (also it is more about performance). With hooks situation appears to be somewhat different and calling it as function is more anti pattern.



from React hooks: call component as function vs render as element

No comments:

Post a Comment