Skip to content

Instantly share code, notes, and snippets.

@rylandg
Last active January 16, 2020 18:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rylandg/774a7edfe6f2a28a36c17a461e9b9295 to your computer and use it in GitHub Desktop.
Save rylandg/774a7edfe6f2a28a36c17a461e9b9295 to your computer and use it in GitHub Desktop.
React parser
const parseOriginalTweet = (body) => {
const parser = new DOMParser();
const doc = parser.parseFromString(body, 'text/html');
return doc.querySelector('blockquote p').innerText || '';
}
const RenderedTweet = ({ tweet }) => {
const now = new Date();
const formattedTime = new Intl.DateTimeFormat(navigator.language, {
hour: 'numeric',
minute: 'numeric',
}).format(now);
const originalTweet = parseOriginalTweet(tweet.original_tweet);
return (
<div>
<p>
<small>
{formattedTime}
</small>
</p>
<p>
Hidden
<a
target='_blank'
href={`https://twitter.com/${tweet.user.name}`}
>
@{tweet.user.name}
</a>’s reply to “${originalTweet}”
</p>
<p>
<a
target='_blank'
href={`https://twitter.com/${tweet.user.name}/status/${tweet.id_str}`}
class='tweet-link'>
Show reply on Twitter
</a>
</p>
</div>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment