反应JSX vs函数调用到当前组件 [英] React JSX vs function call to present component

查看:66
本文介绍了反应JSX vs函数调用到当前组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

推荐答案

是的,第二个速度更快,因为它没有与React.createElement一起安装.请参阅 Philippe Lehoux的精彩文章,讨论了两种方法之间的差异(主要是性能方面的差异).

Yes, 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.

这篇关于反应JSX vs函数调用到当前组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆