问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/47288322/react-jsx-vs-function-call-to-present-component