Your App's render function will be translated to the following JS code for your first example:
render() { return React.createElement( 'div', null, this.renderAFunction('hello') ); }
And the following for the second:
render() { return React.createElement( 'div', null, React.createElement(RenderAFunction, { text: 'hello' }) ); }
While both of them look almost the same, there is one significant difference: laziness . React will execute the RenderAFunction body only if it is installed in the DOM hierarchy.
Slightly your business, but in the following example:
const LazyApp = () => { const heavy = <div><HeavyStuff /></div> // ... return <div>done it</div> } const HardWorkingApp = () => { const heavy = <div>{HeavyStuff()}</div> // ... return <div>done it</div> } const HeavyStuff = () => { // ... do heavy rendering here }
The Lazy app will not do any heavy stuff at all. Maybe this is not very clear from this synthetic example, why at all something like this could be done. But there are examples of the real world when something conceptually similar happens (creating Components without rendering them).
source share