Skip to content

Instantly share code, notes, and snippets.

@levvsha
Last active June 25, 2018 10:31
Show Gist options
  • Save levvsha/71ad7150d9d441ddde6ecb21ea596de6 to your computer and use it in GitHub Desktop.
Save levvsha/71ad7150d9d441ddde6ecb21ea596de6 to your computer and use it in GitHub Desktop.
constructor() {
...
this.getEditorState = () => this.state.editorState;
this.blockRendererFn = customBlockRenderer(
this.onChange,
this.getEditorState
);
}
...
const customBlockRenderer = (setEditorState, getEditorState) => (contentBlock) => {
const type = contentBlock.getType(); // <-- [1]
switch (type) {
case 'SLIDER':
return {
component: EditorSlider, // <-- [2]
props: {
getEditorState, // <-- [3]
setEditorState, // <-- [3]
}
};
default: return null;
}
};
const RenderMap = new Map({ // <-- [4]
SLIDER: {
element: 'div', // <-- [5]
}
}).merge(DefaultDraftBlockRenderMap);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment