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

Demo + API for loading and saving state #139

Closed
YousefED opened this issue Mar 17, 2023 · 8 comments
Closed

Demo + API for loading and saving state #139

YousefED opened this issue Mar 17, 2023 · 8 comments
Assignees

Comments

@YousefED
Copy link
Collaborator

I think this is an important basic req: https://discord.com/channels/928190961455087667/1015169282444894219/1085917095583297606

@slyguy5646
Copy link

slyguy5646 commented Mar 30, 2023

Hey there, I wanted this feature for a project I'm working on so that I could load the state of the editor based on a DB and things like that. I think I have coded up a pretty decent solution if there isn't one already.

@YousefED
Copy link
Collaborator Author

This should have been closed here: #154

See docs @ https://www.blocknotejs.org/docs/editor

@slyguy5646
Copy link

slyguy5646 commented Mar 30, 2023

Is there a way to load this initial content from raw html or the json that tiptap gives back? For me it was a little awkard having to create the blocks and then pass it to the editor as the initial content. And if so, is this content easily storable in a database or the like to load later?

@YousefED
Copy link
Collaborator Author

It's possible to convert to/from HTML, but not recommended. See https://www.blocknotejs.org/docs/converting-blocks

@slyguy5646
Copy link

This should have been closed here: #154

See docs @ https://www.blocknotejs.org/docs/editor

This shows how to store it, thanks.

@slyguy5646
Copy link

slyguy5646 commented Mar 30, 2023

Hey there, sorry to bother again. The only problem I see with this method of loading initial data is doing it with asynchronous data. I tried it utilizing a useEffect hook for data fetching which then sets the data to a state variable. This doesn't load as initial content because the editor is done being instantiated before the data can be fetched. Is there a better way to accomplish this?

@YousefED
Copy link
Collaborator Author

two options

a) you could create the editor only after the data has been fetched
b) you could replace the initial content with replaceblocks when the data has been loaded: https://www.blocknotejs.org/docs/manipulating-blocks#replacing-blocks (little less nice imo)

@slyguy5646
Copy link

Got it thanks so much.

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

3 participants