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

How would I make an API output inside of the Slate text-editor? #5220

Closed
NorkzYT opened this issue Dec 12, 2022 · 2 comments
Closed

How would I make an API output inside of the Slate text-editor? #5220

NorkzYT opened this issue Dec 12, 2022 · 2 comments

Comments

@NorkzYT
Copy link

NorkzYT commented Dec 12, 2022

  How would I make an API output inside of the Slate text-editor?

E.g. (This does not work).

import React, { useState } from 'react';
import { Editor } from 'slate-react';

const MyComponent = () => {
  const [data, setData] = useState([]);

  // Fetch the data from the API and update the component's state
  useEffect(() => {
    fetch('https://my-api.com/data')
      .then(res => res.json())
      .then(json => setData(json));
  }, []);

  return (
    <Editor
      value={data}
      onChange={newData => setData(newData)}
    />
  );
}

Any help would be much appreciated.

I would also like to know why the following does not work.

      <div>
        <Slate
          //className="text-editor"
          editor={editor}
          value={initialValue}
          onChange={onChange}>
          {isLoading ? <div>Loading ...</div> : <Editable value={data.text} />}
        </Slate>
      </div>

Originally posted by @NorkzYT in #5217

@dylans
Copy link
Collaborator

dylans commented Jan 8, 2023

See #4612 (comment)

@NorkzYT
Copy link
Author

NorkzYT commented Feb 22, 2023

Closing due to potential solution as to what dylans commented, and due to inactivity.

@NorkzYT NorkzYT closed this as completed Feb 22, 2023
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

2 participants