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

Support usePuck without custom interfaces or overrides #488

Open
chrisvxd opened this issue May 29, 2024 · 2 comments
Open

Support usePuck without custom interfaces or overrides #488

chrisvxd opened this issue May 29, 2024 · 2 comments

Comments

@chrisvxd
Copy link
Member

chrisvxd commented May 29, 2024

Problem

Users are unable to use the usePuck hook without using a custom interface or overrides, since usePuck must be used within the Puck context, which is rendered within the <Puck> component.

Proposals

Option 1

Optionally extract the context into a separate wrapper.

const Editor = () => {
  const { dispatch } = usePuck();
  
  return <Puck {...} />
}

const Page = () => <PuckContext>
  <Editor />
</PuckContext>

Option 2

Introduce a composable block that retains the default Puck layout, called Default or Layout.

const Editor = () => {
  const { dispatch } = usePuck();
  
  return <Puck.Default {...} />
}

const Page = () => <Puck>
  <Editor />
</Puck >
@janbaykara
Copy link

janbaykara commented Jun 1, 2024

Strongly in favour of Option 1: PuckContext, which mirrors the approach of react-map-gl: https://visgl.github.io/react-map-gl/docs/api-reference/map-provider

I don't want to have to decompose the editor UI in order to update Puck's internal state.

@chrisvxd
Copy link
Member Author

chrisvxd commented Jun 3, 2024

@janbaykara I don't think there is a requirement to decompose in option 2 - it's mostly semantic

Option 1 vs option 2:

  • Puck.Context vs Puck
  • Puck vs Puck.Default

The reason I introduced option 2 was because I don't want to introduce a breaking change to how Puck's context is defined by requiring users to specify a PuckContext wrapper. You could get around that by checking whether or not the Puck component is wrapped within a PuckContext, and only setting up the context inside Puck if there's no wrapper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants