question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I wrote my own implementation of React container for Editor.js, and instead of creating separate package I’d like to volunteer my contributions and help here. Example use case would look like:

import { Editor, useEditorRef } from 'react-editor-js'

const MyComponent = ({ initialData }) => {
  const [ref, { save, loading /* etc. */ }] = useEditorRef()

  const onSave = useCallback(async () => {
    const values = await save()
    console.log(values)
  }, [])

  return (
    <Editor ref={ref} data={initialData} holder="editor-js" /* etc. */>
    { !loading && <button onClick={onSave}>Save</button> }
  )
}

Where useEditorRef is optional and can be replaced with standard useRef. That will allow you to access EditorJS instance with all standard methods at ref.current.

Does this sound like a good idea for this repo?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
hboylancommented, Feb 5, 2020

Appreciate the example @Jungwoo-An!

Just wanted to add an auto-save version I adapted in case others find this issue.

import EditorJS from '@editorjs/editorjs'
import React, { useCallback, useRef } from 'react'
import EditorJs from 'react-editor-js'

import { EDITOR_JS_TOOLS } from './tools'

export const Editor = () => {
  const editorRef = useRef<EditorJS>()

  const handleChange = useCallback(async () => {
    const data = await editorRef.current?.save()
    if (data) {
      console.log(data)
    }
  }, [])

  return (
    <EditorJs
      tools={EDITOR_JS_TOOLS}
      instanceRef={instance => (editorRef.current = instance)}
      onChange={handleChange}
    />
  )
}

2reactions
Jungwoo-Ancommented, Jan 2, 2020

@Tymek Hi! First of all, thanks for your interest! 😍

I thought about this proposal, but i think it is not necessary feature. because It can already use with the react hook. (Example)

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Introducing Hooks
Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class. ... This...
Read more >
@apollo/react-hooks - Apollo GraphQL Docs
A GraphQL query document parsed into an AST by graphql-tag . Optional for the useQuery Hook since the query can be passed in...
Read more >
useState, useCallback, useEffect - React Native v2
Hooks are placed inside the component, as high as possible, always above the return statement. The useState hook returns an array of two...
Read more >
React Hooks cheat sheet: Best practices with examples
In this tutorial, we'll outline some React Hooks best practices and highlight some use cases with examples, from simple to advanced scenarios.
Read more >
The Guide to Learning React Hooks (Examples & Tutorials)
Learn all about React Hooks with this hands-on guide. Includes tutorials and code examples on using hooks for state and effects, for context...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found