solidjs/solid-start

Use `clientOnly` without isolating component in its own file

Open

#1,929 创建于 2024年8月7日

在 GitHub 查看
 (4 评论) (0 反应) (0 负责人)HTML (332 fork)batch import
help wanted

仓库指标

Star
 (4,187 star)
PR 合并指标
 (平均合并 22小时 5分钟) (30 天内合并 3 个 PR)

描述

What is this request related to?

Request

📋 Suggested

https://docs.solidjs.com/solid-start/reference/client/client-only

📋 General description or bullet points

Provide a way of using clientOnly without creating a separate file. Code wise, this could be more ergonomic.

Could also create a helper function to directly translate component function to client only component.

import { clientOnly } from "@solidjs/start"

function ClientOnlyComponent() {
  const location = window.document.location
  return <div>{location.href}</div>
}

type ResolveClientComponent = (value: {
  default: Component
}) => void

export default clientOnly(
  () =>
    new Promise((resolve: ResolveClientComponent) => {
      resolve({ default: ClientOnlyComponent })
    }),
)

🖥️ Reproduction of code samples in StackBlitz

StackBlitz doesn't support solid-start

贡献者指南