SolidStart 仅在客户端进行渲染。

huangapple go评论59阅读模式
英文:

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.

https://www.solidjs.com/docs/latest/api#isserver

huangapple
  • 本文由 发表于 2023年3月7日 02:28:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/75654517.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定