承诺拒绝ID:0 sqlite-reactect
从数据库中检索数据或写入数据库,我正在遇到问题。 初始化成功了
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):错误:无效钩子 称呼。钩子只能在功能的身体内部调用 成分。由于以下原因之一,这可能发生:
- 您可能有不匹配的反应版本和渲染器(例如React Dom)
- 您可能正在打破钩子的规则
- 您可能在同一应用中拥有多个react的副本,请参见 https:// .org/link/link/hook-call 有关如何调试的提示 并解决此问题。错误:无效的挂钩呼叫。钩只能是 称为功能组件的身体内部。这可能发生 由于以下原因之一:
- 您可能有不匹配的反应版本和渲染器(例如React Dom)
- 您可能正在打破钩子的规则
- 您可能在同一应用中拥有多个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:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- 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:- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论