https://codesandbox.io/s/busy-paper-w39kvw?file=/src/components/Comments.js:141-200
const initialState = {
comments: [
{
id: 1,
username: "Kevin",
date: "3 hours ago",
text: "Hello",
votes: 12,
upvoted: false,
downvoted: false,
comments: []
}
]
}
在我的注释代码中,我有一个useSelector
const { comments } = useSelector(state => state.comments)
这会在每次添加新注释时呈现所有注释
如图所示,使用react dev tools add-on在组件渲染时高亮显示:https://i.gyazo.com/43a93b6d07a5802d91d9f68684e5ded5.mp4
我试着用React.memo
来记下这条 comments ,但我不确定为什么不起作用.添加 comments 时,是否仍有停止呈现所有 comments 的方法?