Reactjs 无法使用react挂钩设置状态

Reactjs 无法使用react挂钩设置状态,reactjs,typescript,react-hooks,Reactjs,Typescript,React Hooks,为对象设置状态的这段代码对我不起作用 const [showCommentPopup, setShowCommentPopup] = useState({ showPopUp: false, commentText: '',type: ''} as CommentPopUp); <Button aria-label="addComment"

为对象设置状态的这段代码对我不起作用

  const [showCommentPopup, setShowCommentPopup] = useState({ showPopUp: false, commentText: '',type: ''} as CommentPopUp);


                             <Button
                              aria-label="addComment"
                              onClick={() => setShowCommentPopup({showPopUp: true, type: expenseType, commentText: comments || ''}) 
                              }
                              data-testid="add-comment"
                            >
const[showCommentPopup,setShowCommentPopup]=useState({showPopUp:false,commentText:'',键入:'}作为CommentPopUp);
setShowCommentPopup({showPopUp:true,type:expenseType,commentText:comments | |'''})
}
data testid=“添加注释”
>

尝试删除您的
,如弹出的
。你为什么需要这个?

请说得更具体些:“不适合我”是相当含糊的。您如何知道(仅基于您发布的代码)它是否有效?哪些不起作用,请更具体一些。您可以控制台.log(showCommentPopup)并查看它是否会在单击时更改。她正在使用typescript。正确的方法是
useState({…})
。否则,无法从普通对象推断类型。啊,我的错。我不知道那是打字稿!谢谢你指出这一点