-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 to set default value #357
Comments
import React, { Component } from 'react'
import { EditorState, ContentState, convertFromHTML } from 'draft-js'
import { Editor } from 'react-draft-wysiwyg'
class MyEditor extends Component {
constructor(props) {
super(props)
this.state = {
editorState: EditorState.createWithContent(
ContentState.createFromBlockArray(
convertFromHTML('<p>My initial content.</p>')
)
),
}
}
render() {
return <Editor editorState={this.state.editorState} />
}
}
export default MyEditor |
Thanks @ddelrio1986 , @ok713 I hope that helps, I am closing the issue - plz feel free to re-open if you need more information. |
in the case how do I get the last value from the database and enter in the editor? |
textAlign center not working on defaultEditorState? anyone have an idea about this? thanks. |
@ddelrio1986 cant type on wysiwyg
|
@justinlazaro-ubidy: to make editor an un-controlled component you need to use |
@jpuri is right. You need to still add a normal onChange event handler to handle typing within the component just like with any other controlled input component. |
It works and I can get data into editor, but when I type something then it auto undo all content and not able to write something else. Please someone help me...... import React, { Component } from 'react' class MyEditor extends Component { My initial content. ')) ), } } render() { export default MyEditor |
sdfdsfdsfsdfsdfdsfsdfsd |
how about set default value in react hooks? please help |
|
is there any way to set default value without |
value.replace(/(<([^>]+)>)/gi, ""); |
Found a solution with hooks: import {
EditorState,
convertToRaw,
ContentState,
convertFromHTML
} from "draft-js"
const YourComponent = ({ props }: YourComponentProps) => {
const [editorState, setEditorState] = useState(() => {
const blocksFromHTML = convertFromHTML(data)
const contentState = ContentState.createFromBlockArray(
blocksFromHTML.contentBlocks,
blocksFromHTML.entityMap
)
return EditorState.createWithContent(contentState)
}
)
... |
Please check if the solution above works for you. |
This solution works for me. Thank you. |
Not able to Edit by doing:
|
Many thanks |
Thankyou so much! |
Works, but lost all formatting :(
|
import React, { Component } from 'react'; const Editor = dynamic( let htmlToDraft = null; export default class EditorConvertToHTML extends Component {
} |
Did you find a workaround on this to also keep the formatting? Thanks in advance |
Putting it here in case anyone who wants to have default value coming from the backend ( to mock db I've used the localStorage )
|
No description provided.
The text was updated successfully, but these errors were encountered: