Created
August 20, 2017 10:01
-
-
Save erika-dike/741021505a95a88e45229e7f91863d97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import getUrls from 'get-urls'; | |
| import linkifyHtml from 'linkifyjs/html'; | |
| import PropTypes from 'prop-types'; | |
| import { | |
| PostMediaContainer, | |
| PostTextContainer, | |
| } from './components'; | |
| const PostContent = ({ content }) => { | |
| const urls = Array.from(getUrls(content)); // returns a set | |
| let contentToBeRendered = content; | |
| let mappedUrls; | |
| if (urls.length) { | |
| contentToBeRendered = linkifyHtml(content); | |
| mappedUrls = urls.map((url, index) => | |
| <PostMediaContainer key={index} url={url} />, | |
| ); | |
| } | |
| return ( | |
| <div> | |
| <PostTextContainer text={contentToBeRendered} /> | |
| {mappedUrls} | |
| </div> | |
| ); | |
| }; | |
| PostContent.propTypes = { | |
| content: PropTypes.string.isRequired, | |
| }; | |
| export default PostContent; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment