如果我将另一个用户添加到我的表中,我想将最后一个现有数据增加到加1

这是我的 data.js。如果我将另一个用户添加到我的表中,我想将最后一个现有数据增加到加 1。我将以前生成的 id 中的 nanoid 用于我的 userRows 数据。但我希望我的 id 增加 1。例如,我创建的最后一个用户的 ID 为 20,我希望我的下一个用户是 21。有人可以帮助我或指导我修复生成的 id 吗?提前谢谢你。

export const userRows = [
  {
    id: 1,
    username: "Richmond",
    fullName: "Richmond Vicente Ramil",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Richmond@gmail.com",
    age: 22,
  },
  {
    id: 2,
    username: "Fernand",
    fullName: "Fernaan Million Galeron",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "passive",
    email: "Fernand@gmail.com",
    age: 23,
  },
  {
    id: 3,
    username: "Jerson",
    fullName: "Jerson Tablatin Aganon",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Jerson@gmail.com",
    age: 23,
  },
  {
    id: 4,
    username: "Jyvonn",
    fullName: "Jyvonn Nool Juan",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Jyvonn@gmail.com",
    age: 24,
  },
  {
    id: 5,
    username: "Mike",
    fullName: "Mike Tyson Kid",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "pending",
    email: "Mike@gmail.com",
    age: 20,
  },
  {
    id: 6,
    username: "Mark",
    fullName: "Mark Bryant Cleofas",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "passive",
    email: "Mark@gmail.com",
    age: 26,
  },
  {
    id: 7,
    username: "Bryan",
    fullName: "Bryan Brenna Tiofelo",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Bryan@gmail.com",
    age: 32,
  },
  {
    id: 8,
    username: "Jonathan",
    fullName: "Jonathan Nool Cleofas",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Jonathan@gmail.com",
    age: 19,
  },
  {
    id: 9,
    username: "Walter",
    fullName: "Walter Mike Mart",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "pending",
    email: "Walter@gmail.com",
    age: 30,
  },
  {
    id: 10,
    username: "Vincent",
    fullName: "Vincent Abdul Saudi",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "pending",
    email: "Vicent@gmail.com",
    age: 42,
  },
  {
    id: 11,
    username: "Galeon",
    fullName: "Galeon Mark Apollo",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Galeon@gmail.com",
    age: 46,
  },
  {
    id: 12,
    username: "Brandon",
    fullName: "Brandon Vicente Ramil",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "passive",
    email: "Brandon@gmail.com",
    age: 25,
  },
  {
    id: 13,
    username: "Kenneth",
    fullName: "Kenneth Timothy Sison",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "passive",
    email: "Keneth@gmail.com",
    age: 26,
  },
  {
    id: 14,
    username: "Alexis",
    fullName: "Alexis Delos Santos",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Alexis@gmail.com",
    age: 22,
  },
  {
    id: 15,
    username: "John",
    fullName: "John Kyle Abrera",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "John@gmail.com",
    age: 28,
  },
  {
    id: 16,
    username: "Patrick",
    fullName: "Patrick Martin Nievera",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "pending",
    email: "Patrick@gmail.com",
    age: 23,
  },
  {
    id: 17,
    username: "Steve",
    fullName: "Steve Work Job",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Steve@gmail.com",
    age: 24,
  },
  {
    id: 18,
    username: "Ralph",
    fullName: "Ralph Dela Pena",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "passive",
    email: "Ralph@gmail.com",
    age: 46,
  },
  {
    id: 19,
    username: "Chandler",
    fullName: "Chandler Dark Mosquito",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Chandler@gmail.com",
    age: 29,
  },
  {
    id: 20,
    username: "Reyster",
    fullName: "Reyster John Car",
    img: "https://demos.themeselection.com/materio-mui-react-nextjs-admin-template/demo-1/images/avatars/3.png",
    status: "active",
    email: "Reyster@gmail.com",
    age: 29,
  },
];

我想生成 ID。如果我添加一个新用户,下一个 id 将是 21

const newUser = {
      //I want to put the next id which is 21 here on my newUser object and id property
      //id: ID 21 here ,
      username: addFormData.username,
      img: file
        ? URL.createObjectURL(file)
        : "https://yt3.ggpht.com/CblhnSj8-Q6Ptr6n8Nq1e3wB4gadeNM_IYjDma89iNfuTrAfsMwogvkPFb6JbG8XS-fdBnN5Plk=s88-c-k-c0x00ffffff-no-rj-mo",
      fullName: addFormData.fullName,
      email: addFormData.email,
      age: addFormData.age,
      status: addFormData.status,
    };

© 版权声明
THE END
喜欢就支持一下吧
点赞240赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容