import React from 'react' ; import { Entity } from 'draft-js' ; const Media = ( { block } ) => { 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 ;