英文:
SolidStart client side only rendering
问题
Solid Start中是否有一种方法只在客户端渲染组件?
就像在Next.js中我们可以使用dynamic
来设置SSR为false
一样。在SolidJS中是否有替代方法?
我尝试在createEffect
中导入模块。
英文:
Is there any way to render a component on the client side only in Solid Start.
Just like in next js we can use dynamic to get ssr false. Is there any alternative for that in SolidJS?
I tried to import module in createEffect.
答案1
得分: 1
有一个来自 solid-start
的实验性 API unstable_clientOnly
:
在服务器端,它将呈现
null
,或者如果传递了任何fallback
,它将呈现fallback
。这可以帮助避免布局转换。
https://github.com/solidjs/solid-start/issues/320
它在内部使用了 solid-js/web
中的 isServer
:
这表示代码正在作为服务器或浏览器捆绑包运行。由于底层运行时将其导出为一个常量布尔值,它允许捆绑器从各自的捆绑包中消除代码和它们使用的导入。
https://www.solidjs.com/docs/latest/api#isserver
英文:
There is an experimental API unstable_clientOnly
exported from solid-start
:
> On the server it will render null
or will render the fallback
if you pass it any. This can help avoid layout shifts.
https://github.com/solidjs/solid-start/issues/320
It uses isServer
from solid-js/web
internally:
> This indicates that the code is being run as the server or browser bundle. As the underlying runtimes export this as a constant boolean it allows bundlers to eliminate the code and their used imports from the respective bundles.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论