0

I am confused by this. I couldn't find a solution.

Returns an error:

./src/components/TextEditor.js Attempted import error: 'slate-react' does not contain a default export (imported as 'Editor').

import React, { Component } from 'react'
import Editor from 'slate-react'
import Value from 'slate'

const initialValue = Value.fromJSON({
    document: {
        nodes: [
            {
                object: 'block',
                type: 'paragraph',
                nodes: [
                    {
                        object: 'text',
                        leaves: [
                            {
                                text: 'A line of text in a paragraph.',
            },
        ],
    }, ],
}, ],
},
})



export default class TextEditor extends Component {

    state = {
        value: initialValue,
    }

    onChange = ({ value }) => {
        this.setState({ value })
    }

    render() {
        return (
            <Editor value={this.state.value} onChange={this.onChange} />
        )
        }
}

index

import TextEditor from './TextEditor';

export { TextEditor };

1 Answers1

1

Editor and Value are named exports.

Replace:

import Editor from 'slate-react'
import Value from 'slate'

with

import { Editor } from 'slate-react'
import { Value } from 'slate'

Those being named exports means you that have to import the precise name which is exported, and this goes within curly braces.

See Slate doc

Michel
  • 26,600
  • 6
  • 64
  • 69
  • Thanks. And now, I have a new error: Attempted import error: 'Editor' is not exported from 'slate-react'. – isyuricunha Oct 25 '21 at 22:42
  • 1
    Current doc, which I linked, imports it from slate-react, but it looks like in former versions it was exported by `slate`, that is, try `import { Editor, Value } from 'slate'` – Michel Oct 25 '21 at 22:48
  • I read the current doc... I fix, but, now I have another error: "Attempted import error: 'Value' is not exported from 'slate'." – isyuricunha Oct 25 '21 at 22:57
  • 1
    What version of slate are you using? – Michel Oct 26 '21 at 09:32