世界上最伟大的投资就是投资自己的教育
liu_hao0813
id 12887
15 hours 55 minutes 27 seconds 舵主 研究生
-
老师,我的 likepost 方法有调用,但是页面没有更新,
import React, {useState, useEffect} from "react";
import { Button, Icon, Label } from "semantic-ui-react";
import { Link } from 'react-router-dom'
import { LIKE_POST_MUTATION } from '../graphql/postgql'
import { useMutation } from "@apollo/react-hooks";function LikeButton({user, post: {id,likes, likesCount}}){
const [liked, setLiked] = useState(false)
const [likePost] = useMutation(LIKE_POST_MUTATION, {
variables: {postId: id}
})
useEffect(()=>{
if(user && likes.find(like => like.username === user.username)){
setLiked(false)
}else{
setLiked(true)
}
}, [user, likes])const likeButton = user ? (
) : (
)
return (
onClick={likePost}>
{ likeButton }
{likesCount}
)
}export default LikeButton
-
老师,这个只能插到后面,不能插的在前面吗,我看到网上有说 apollo 支持自动更新 cache, 没有找到怎么配置,还有,有没有办法屏蔽缓存
© 汕尾市求知科技有限公司 | Rails365 Gitlab | Qiuzhi99 Gitlab | 知乎 | b 站 | 搜索
粤公网安备 44152102000088号 | 粤ICP备19038915号
Top