Very new to React/Javascript here - usually a back end developer.
I have a component class (RichEditorExample) which contains an editor component. I want to be able to access the value of the Editor (EditorState) from outside the class so I can use the value elsewhere. Is there a way I could access the value or pass it back as a function?
code cut down for clarity:
const App = () => {
class RichEditorExample extends React.Component {
constructor(props) {
super(props);
this.state = { editorState: EditorState.createEmpty() };
this.onChange = (editorState) => {
this.setState({ editorState });
}
.....
return (
<div className="RichEditor-root">
<BlockStyleControls
editorState={editorState}
onToggle={this.toggleBlockType}
/>
<InlineStyleControls
editorState={editorState}
onToggle={this.toggleInlineStyle}
/>
<div className={className} onClick={this.focus}>
<Editor
editorState={editorState}
onChange={this.onChange}
/>
</div>
</div>
);
.....
}
return (
<div>
<RichEditorExample />
<some code to access the editor value here>
</div>
);
}