承诺拒绝ID:0 sqlite-reactect

发布于 2025-02-01 17:03:49 字数 1731 浏览 1 评论 0原文

从数据库中检索数据或写入数据库,我正在遇到问题。 初始化成功了

    export const getDataFromDB = async () => {

  const dispatch = useDispatch();

  try {
    const db = await getDB();
    await db.transaction(async tx => {
      await tx.executeSql(
        'SELECT UserName, Password, RememberMe, MapView, DrawEdits, NetworkIP, Port, Auth FROM UsersInformation',
        [],
        (tx, results) => {
          console.log('Database readed');
          var len = results.rows.length;
          if (len > 0) {
            let item = results.rows.item(0);
            dispatch(setUsername(item.UserName));
            dispatch(setPassword(item.Password));
            dispatch(setRememberMe(item.RememberMe));

            dispatch(setMapView(item.MapView));

            dispatch(drawEdits(item.DrawEdits));

            dispatch(networkIp(item.NetworkIP));
            dispatch(networkPort(item.Port));
            dispatch(networkAuth(item.Auth));
          }
        },
      );
    });
  } catch (error) {
    console.log(error.message);
  }
};

表的

可能的未置信的承诺拒绝(ID:3):错误:无效钩子 称呼。钩子只能在功能的身体内部调用 成分。由于以下原因之一,这可能发生:

  1. 您可能有不匹配的反应版本和渲染器(例如React Dom)
  2. 您可能正在打破钩子的规则
  3. 您可能在同一应用中拥有多个react的副本,请参见 https:// .org/link/link/hook-call 有关如何调试的提示 并解决此问题。错误:无效的挂钩呼叫。钩只能是 称为功能组件的身体内部。这可能发生 由于以下原因之一:
  4. 您可能有不匹配的反应版本和渲染器(例如React Dom)
  5. 您可能正在打破钩子的规则
  6. 您可能在同一应用中拥有多个react的副本,请参见 https:// .org/link/link/hook-call 有关如何调试的提示 并解决此问题。

I am having a problem retrieving data from or writing to my database. The initialization of the table is successful but if I put any other function I get the following warning and the code doesn't work

    export const getDataFromDB = async () => {

  const dispatch = useDispatch();

  try {
    const db = await getDB();
    await db.transaction(async tx => {
      await tx.executeSql(
        'SELECT UserName, Password, RememberMe, MapView, DrawEdits, NetworkIP, Port, Auth FROM UsersInformation',
        [],
        (tx, results) => {
          console.log('Database readed');
          var len = results.rows.length;
          if (len > 0) {
            let item = results.rows.item(0);
            dispatch(setUsername(item.UserName));
            dispatch(setPassword(item.Password));
            dispatch(setRememberMe(item.RememberMe));

            dispatch(setMapView(item.MapView));

            dispatch(drawEdits(item.DrawEdits));

            dispatch(networkIp(item.NetworkIP));
            dispatch(networkPort(item.Port));
            dispatch(networkAuth(item.Auth));
          }
        },
      );
    });
  } catch (error) {
    console.log(error.message);
  }
};

The error is the following

Possible Unhandled Promise Rejection (id: 3): Error: Invalid hook
call. Hooks can only be called inside of the body of a function
component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug
    and fix this problem. Error: Invalid hook call. Hooks can only be
    called inside of the body of a function component. This could happen
    for one of the following reasons:
  4. You might have mismatching versions of React and the renderer (such as React DOM)
  5. You might be breaking the Rules of Hooks
  6. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug
    and fix this problem.

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

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

发布评论

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