import { Entity } from 'draft-js' ; import React from 'react' ; interface MediaProperties { block : any ; } class Media extends React . Component < MediaProperties > { render ( ) { const { block } = this . props ; const entityKey = block . getEntityAt ( 0 ) ; const entity = entityKey ? Entity . get ( entityKey ) : undefined ; if ( ! entity ) { return < span className = 'remove-block' / > ; } const { href , target , ... mediaProps } = entity . getData ( ) ; const entityType = entity . getType ( ) . toLowerCase ( ) ; if ( entityType === 'image' ) { const media = < img { ... mediaProps } alt = '' / > ; if ( href ) { return ( < a href = { href } target = { target || '_blank' } > { media } < /a>); } return media ; } else if ( entityType === 'iframe' || entityType === 'script' ) { return < div className = 'noscript' dangerouslySetInnerHTML = { { __html : mediaProps . src } } />; } else { throw new Error ( 'Sorry, media type not found.' ) ; } } } export default Media ;