14
const Component = ({ text }) => (
  <div>{text}</div>
)

const Example = () => (
  <div>
    <Component text="123" />
    {Component({ text: "123" })}
  </div>
)

Is there any difference between the two methods of rendering? Which is preferred and why?

Avery235
  • 4,756
  • 12
  • 49
  • 83
  • Both will end up as `React.createElement("div", null, text );` calls :) I would use the JSX notation, as it makes it obvious that a Component will be rendered. – pawel Nov 14 '17 at 14:41

1 Answers1

13

I recommend that you don't call function components but render them instead. This approach may lead to unexpected behaviors (mainly if you are using hooks). For more details see Don't call a React function component by Kent C. Dodds.

However the second is faster because it's not mounted with React.createElement. See this great article by Philippe Lehoux that talks about the differences (mainly in performance) between both approaches.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Tiago Alves
  • 2,290
  • 13
  • 32