Search code examples
reactjsdraftjs

How to select and remove an atomic block


I have a an atomic block which displays an image. I want to add a 'click-to-delete' button in the top corner of the image.

It seems like using Modifier.removeRange would work but how do I get the selection state of the atomic block?

Or is there an easier way? like removeBlockWithKey(key) ?


Solution

  • make a custom atomic block. then you can get the block key with this.props.block.getKey(). then create the SelectionState with the key like

    SelectionState.createEmpty(key).merge({focusOffset:this.props.block.getText().length})