stacker.news/components/comments.js
2021-04-22 17:14:32 -05:00

24 lines
595 B
JavaScript

import { useQuery } from '@apollo/client'
import Comment, { CommentSkeleton } from './comment'
export default function Comments ({ query, ...props }) {
const { loading, error, data } = useQuery(query)
if (error) return <div>Failed to load!</div>
if (loading) {
const comments = new Array(3).fill(null)
return comments.map((_, i) => (
<div key={i} className='mt-2'>
<CommentSkeleton skeletonChildren />
</div>
))
}
return data.comments.map(item => (
<div key={item.id} className='mt-2'>
<Comment item={item} {...props} />
</div>
))
}