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

Error: Invariant failed #1

Open
JensSteckhan opened this issue Mar 14, 2019 · 1 comment
Open

Error: Invariant failed #1

JensSteckhan opened this issue Mar 14, 2019 · 1 comment

Comments

@JensSteckhan
Copy link

JensSteckhan commented Mar 14, 2019

Thanks for the great tutorial.
However, with newer versions of slate-react, pressing the toolbar buttons no longer seems to work:
The following error occurs:
Error: Invariant failed: As of Slate 0.42.0, value object are no longer schema-aware, and the value.change() method is no longer available. Use the editor.change() method on the new Editor controller instead.

@JensSteckhan
Copy link
Author

II managed to fix it locally with the following changes. However, the code that you checked in seems to run into other problems with newer versions as well, so I'll simply document my changes. Maybe it is helpful for someone ;-)

...add a reference to editor in TextEditor.js:

ref = editor => {
        this.editor = editor
}

...initialize it in render():

<Editor
                    value={this.state.value}
                    ref={this.ref}
                    onChange={this.onChange}
                    onKeyDown={this.onKeyDown}
                    renderMark={this.renderMark}
                />

...and change the onMarkClick to the following:

onMarkClick = (e, type) => {
        e.preventDefault();
        this.editor.toggleMark(type);
    }

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

No branches or pull requests

1 participant