Slate.js plugin | Error: The `useSlate` hook must be used inside the <Slate> component's context.

default discord avatar
franckmartin
6 months ago
1 1

Hi ! 🙂

I copied the largeBody Slate.js plugin from the public-demo to my repo and it works perfectly. I did a blockquote plugin based on this model and it works well too. But when I'm trying to use slightly more sophisticated plugins like hr, I get the following error :

The `useSlate` hook must be used inside the <Slate> component's context.

Do you have any idea why the <Slate> context is not available?
I installed the slate package in version 0.91.4 and the slate-react package in version 0.91.10

Thanks for your help

  • discord user avatar
    jmikrut
    Payload Team
    6 months ago

    Hey there - this is because you have two copies of Slate in use - one local, and one within Payload. Instead of installing a separate copy of slate / slate-react, just use Payload's copies.

    You could also try making sure to match the slate and slate-react versions exactly to what Payload uses internally in its own package.json.

    Last thing, if you do want to have additional copies of Slate installed, you could write a Webpack alias to make sure that when you import Slate, it always points to the same copy of Slate.

    This is a React problem more than anything, with how it handles context / etc. But this should be what you need here.

    1 reply
  • default discord avatar
    franckmartin
    6 months ago

    Thank you so much @jmikrut ! It works perfectly

Open the post
Continue the discussion in GitHub
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.