Ever understand the difference between gender and your sexual orientation?
P粉562845941
2023-08-15 15:53:07
<p>In Inferno, when trying to define a child element shape at compile time, there are two ways to define the child element as text: </p>
<pre class="brush:php;toolbar:false;">function Hello() {
let h = "Hello";
return (
<p $HasTextChildren>
{h}
</p>
);
}</pre>
<pre class="brush:php;toolbar:false;">import { createTextVNode } from "inferno";
function Hello() {
let h = "Hello";
return (
<p $HasVNodeChildren>
{createTextVNode(h)}
</p>
);
}</pre>
<p>What is the difference between these two methods? </p>
As far as the final result is concerned, there is no difference. Performance-wise, however, the former is slightly faster. But the restriction is that child elements must be text only. There may be situations where you want the text and other content as child elements. In this case you can use
createTextVNode()
with one of the appropriate flags, one of which is$HasVNodeChildren
. You can see the list of flags in the documentation: https://www.infernojs.org/docs/guides/optimizationsAs an additional note, you don't have to define the shape of the child elements yourself if the compiler can see it at compile time. Therefore, there is no need to write like this:
You can simply write: