Does Next.js support conditional rendering and pre-rendering of unrendered HTML?
P粉450744515
2023-08-14 17:48:55
<p>Next.js pre-renders HTML on a page that only displays when a certain button is clicked? For example, when we have tabs, does it render the content of the tab that is not yet shown? </p>
Not only for Next.js, but also for React, it will depend on how you show/hide the component conditionally, especially if it is hidden by CSS or JavaScript. Here is an example:
In the first example, when the
isVisible
property is set tofalse
, an empty fragment will be rendered. An empty fragment will not produce any HTML.In the second example, we just changed the
display
property of the CSS based on the attribute, and the generated HTML will still be included in your HTML without being visible.