Ever understand the difference between gender and your sexual orientation?
P粉562845941
P粉562845941 2023-08-15 15:53:07
0
1
421
<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>
P粉562845941
P粉562845941

reply all(1)
P粉762730205

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/optimizations

As 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:

function Hello() {
  return <p $HasTextChildren>Hello</p>;
}

You can simply write:

function Hello() {
  return <p>Hello</p>;
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!