editor.save() is not a function in React functional component
See original GitHub issueEditorjs while imported in React functional component isn’t working when calling function to save data.
const editor = new EditorJs({
holder:'editorjs',
placeholder: 'Let`s write an awesome story!',
tools: {
header : {
class: Header,
inlineToolbar:true,
shortcut:"CTRL+SHIFT+H",
config: {
placeholder:'Enter Your text'
}
}
},
data:{}
})
const output = document.getElementById('output')
function Save() {
editor.save().then(data => {
output.innerHTML = data
})
}
export default function Editor() {
return (
<div>
<h1>Create Your Post</h1>
<div id="editorjs" style={{border:'1px solid #ddd', marginBottom:'1rem'}} mx={4}></div>
<Button variant="contained" color="primary" onClick={Save()}>Save Me</Button>
<code id="output"></code>
</div>
)
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:7
Top Results From Across the Web
React functional components- say its not a function
my functional component. const LiteraryPage = props => { if (Object.keys(mainData).
Read more >State Management within React Functional Components with ...
For simple types, using const keyword protects the state from direct mutation. For object types, nothing stops you from updating the object's properties....
Read more >Render Props - React
A component with a render prop takes a function that returns a React element and calls it instead of implementing its own render...
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 >React Functional Components, Props, and JSX - freeCodeCamp
If you revisit the example code at the top of this post, you'll see that the JSX code is being returned by a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
onClick={Save}
will callSave
on click, butonClick={Save()}
is going to callSave
on render and nothing on click asSave
is not returning anythingI agreed with @mupkoo that your ‘const editor = new EditorJs({holder:‘editorjs’,…’ is executed before ‘<div id=“editorjs”…’ is rendered, so not such element with the id can provide EditorJs’s constructor.