Skip to content

Instantly share code, notes, and snippets.

@tharsheblows
Last active July 25, 2020 09:55
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 tharsheblows/5150e3cd9f0db7689f45086d8803ed49 to your computer and use it in GitHub Desktop.
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
/** @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