import React from 'react'; import { useMutation } from '@apollo/react-hooks' import classes from './Posts.module.css' import GET_POSTS from '../../apollo/queries/posts' import DEL_POST from '../../apollo/mutations/delPost' const Posts = ({ data }) => { const [isError, setIsError] = React.useState({ status: false, error: null }) const [delPost] = useMutation(DEL_POST, { update(cache, { data: { delPost } }) { const { posts } = cache.readQuery({ query: GET_POSTS }) cache.writeQuery({ query: GET_POSTS, data: { posts: posts.filter(post => post.id !== delPost.id) } }) } }) const btnHandlerDel = id => { delPost({ variables: { id } }).catch(error => { console.log(error) setIsError({ status: true, error }) }) } if (data.length <= 0) return "No posts..." return ( <> {isError.status ?
{post.description}