Last active
July 25, 2020 09:55
-
-
Save tharsheblows/5150e3cd9f0db7689f45086d8803ed49 to your computer and use it in GitHub Desktop.
Renders one comment if given a comment object from the WP REST API
This file contains 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
/** @jsx jsx */ | |
import { jsx } from 'theme-ui' | |
import React from 'react' | |
import sanitizeHtml from 'sanitize-html' | |
import Date from './Date' | |
const Comment = ({ comment }) => { | |
const { | |
date, | |
content, | |
author_name, | |
} = comment | |
const commentContent = sanitizeHtml(content.rendered, { allowedTags: ['p', 'br'] }) | |
return ( | |
<> | |
<div | |
sx={{ | |
variant: `cards.white`, | |
padding: [1, 2, 3], | |
mb: 1, | |
border: t => `1px solid ${t.colors.shadePink}`, | |
borderRadius: `5px`, | |
color: `text`, | |
}} | |
> | |
From {author_name} on <Date date={date} /> | |
<div dangerouslySetInnerHTML={{ __html: commentContent }} /> | |
</div> | |
</> | |
) | |
} | |
export default Comment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment