Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[effector-react] Add 'use client' directive to gate as component #1067

Open
domosedov opened this issue May 20, 2024 · 1 comment
Open

[effector-react] Add 'use client' directive to gate as component #1067

domosedov opened this issue May 20, 2024 · 1 comment
Labels
effector-react effector-react package nextjs Integration with next.js framework RFC Request for Comments

Comments

@domosedov
Copy link
Contributor

domosedov commented May 20, 2024

Proposal

Mark Gate Component with 'use client' directive

Use case

// model.ts
export const PageGate = createGate()

Now we cant do like this

// react server component
export default function Page() {
  return (
    <>
      <PageGate/>
    </>
  )
}

Error

Error: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component

Current solution

// gate.tsx
'use client'
import {PageGate as Gate} from './model.ts'
export const PageGate = () => {
useGate(Gate)
return null
}
@domosedov domosedov added the RFC Request for Comments label May 20, 2024
@zerobias zerobias added effector-react effector-react package nextjs Integration with next.js framework labels May 21, 2024
@zerobias
Copy link
Member

Its ok to improve this case as we eventually have to deal with that anyway.

Open questions are only implementation details:

  • The library is bundled as single file and we don't want to change that, so is it ok to add 'use client' at the top of the whole module?
  • How it should be implemented with rollup? There could be sourcemap issues if we just add a directive after the build is complete. Is there a rollup plugin for that?

I suggest waiting until the release of react 19 to learn from the experience of other libraries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effector-react effector-react package nextjs Integration with next.js framework RFC Request for Comments
Projects
None yet
Development

No branches or pull requests

2 participants