Applying Custom Formatting
Applying Custom Formatting
class App extends React.Component {
state = {
value: initialValue,
}
onChange = ({ value }) => {
this.setState({ value })
}
onKeyDown = (event, editor, next) => {
if (event.key != '`' || !event.ctrlKey) return next()
event.preventDefault()
const isCode = editor.value.blocks.some(block => block.type == 'code')
editor.setBlocks(isCode ? 'paragraph' : 'code')
return true
}
render() {
return (
<Editor
value={this.state.value}
onChange={this.onChange}
onKeyDown={this.onKeyDown}
renderBlock={this.renderBlock}
/>
)
}
renderBlock = (props, editor, next) => {
switch (props.node.type) {
case 'code':
return <CodeNode {...props} />
default:
return next()
}
}
}Last updated