They don't have the slate context either, they just use the useSlate hook. As far as i can tell my code looks quite similar but somehow i get the mentioned error.
this is my buttons code:
import {ElementButton} from '@payloadcms/richtext-slate';
import React, {useCallback} from 'react';
import {Transforms} from 'slate';
import {ReactEditor, useSlate} from 'slate-react';
import {isElementActive} from '../../../../helpers/isElementActive';
const baseClass = 'rich-text-invite-button';
const insertButton = (editor) => {
const text = {text: 'Einladungslink'};
const button = {
type: 'invite',
children: [text],
};
const nodes = [button, {children: [{text: ''}]}];
if (editor.blurSelection) {
Transforms.select(editor, editor.blurSelection);
}
Transforms.insertNodes(editor, nodes);
ReactEditor.focus(editor);
};
const ToolbarButton: React.FC<{path: string}> = () => {
const editor = useSlate();
const handleAddInviteLink = useCallback(() => {
insertButton(editor);
}, [editor]);
return (
<ElementButton
format=''
className={[
baseClass,
isElementActive(editor, 'invite') && 'rich-text__button__button--active',
]
.filter(Boolean)
.join(' ')}
onClick={handleAddInviteLink}
>
Einladungs Link
</ElementButton>
);
};
export default ToolbarButton;