模态在react中的卡中删除函数时闭合。为什么?

发布于 2025-01-22 02:03:58 字数 1293 浏览 1 评论 0原文

当有人按导航中的“成员”按钮时,我有一个模态正在触发。模式正常,并包含列出所有成员的卡。代码在这里(样式的组件可能会使JSX标签看起来很奇怪,但很好)

const cards = members.map((member, i) => (
    <Card key={i}>
      <Name>{member.name.charAt(0).toUpperCase() + member.name.slice(1)}</Name>
      <Relationship>
        {member.relationship.charAt(0).toUpperCase() +
          member.relationship.slice(1)}
      </Relationship>
      <ButtonContainer>
        <Button style={{ backgroundColor: "#05848c" }} onClick={ () => handleAddInfo(member._id)}>Add Info</Button>
        <Button onClick={() => handleDelete(member._id)}>Delete</Button>
      </ButtonContainer>
    </Card>
  ));

如果我只有“ phandletelete”中的控制台登录,则可以按下任何卡上的按钮,并且模态很好。但是,当我派遣“删除成员”事件时,该功能可行,但模态突然关闭。我无法弄清可能会触发这一点,并到处都在寻找答案。有人有什么线索吗?这是Redux工具包中的删除函数

const deleteMember = async (memberId, token) => {
  const config = {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  };

  const response = await axios.delete(`http://localhost:5000/api/me/family/${memberId}`, config);
  return response.data;
};

I have a modal that is triggering when someone presses a 'Member' button in the navigation. The modal works fine and contains cards that list all the members. Code is here (styled components might make the jsx tags look odd but it's fine)

const cards = members.map((member, i) => (
    <Card key={i}>
      <Name>{member.name.charAt(0).toUpperCase() + member.name.slice(1)}</Name>
      <Relationship>
        {member.relationship.charAt(0).toUpperCase() +
          member.relationship.slice(1)}
      </Relationship>
      <ButtonContainer>
        <Button style={{ backgroundColor: "#05848c" }} onClick={ () => handleAddInfo(member._id)}>Add Info</Button>
        <Button onClick={() => handleDelete(member._id)}>Delete</Button>
      </ButtonContainer>
    </Card>
  ));

If I just have a console log in the 'handleDelete', the button on any card can be pressed and the modal is fine. However when I dispatch a 'delete member' event, the function works but the modal abruptly shuts down. I can't figure out what might be triggering this and have searched everywhere for an answer. Does anyone have any clues why that might be? Here is the delete function in Redux Toolkit

const deleteMember = async (memberId, token) => {
  const config = {
    headers: {
      Authorization: `Bearer ${token}`,
    },
  };

  const response = await axios.delete(`http://localhost:5000/api/me/family/${memberId}`, config);
  return response.data;
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文