提问人:juan manuel taboada álvarez 提问时间:11/7/2023 更新时间:11/7/2023 访问量:6
树莓派中 react 的异步问题和缓慢的卡顿连接
Asynchrony issue with react in a raspberry Pi and slow stuttering connection
问:
我在访问页面上遇到了问题。我已经在 Raspberry 上运行了 5 个微型和前端(使用 react)。问题是,每当我打开这个东西时,前面都会先加载,然后微处理器完成启动,每次我看到一个卡顿,好像状态变量“加载”从 true 变为 false,然后变回 true,再变为 false......它做了几次闪烁的事情,然后它工作得很好。问题是我无法在本地测试中复制它,我不明白为什么。我试过先启动正面,然后一个接一个地启动微型,但仍然没有在笔记本电脑中出现卡顿。我不明白为什么我会把它放在覆盆子里。覆盆子中的通话仍在“本地”进行,不涉及互联网,因此连接速度慢应该无关紧要。另外,当在开发者模式下使用 Raspberry 时,就像在我的笔记本电脑中一样,使用一些 npm run dev 运行所有内容时,我不会眨眼。 这是相关代码。
动作功能:
export function getBackendStatusAction() {
return async (dispatch) => {
try {
let errorOccurred = false;
const fetchStatus = async (endPoint) => {
try {
const res = await apiFetch('GET', { endPoint });
return res.status;
} catch (error) {
return null;
}
};
const endpoints = ['iam/status', 'administration/status', 'evaluations/status', 'mqtt/status', 'logs/status'];
const results = await Promise.all(endpoints.map((endPoint) => fetchStatus(endPoint)));
results.forEach((status) => {
if (status !== 200) {
errorOccurred = true;
dispatch(backendOffline());
}
});
if (!errorOccurred) {
dispatch(backendOnline());
}
if (errorOccurred) {
setTimeout(() => getBackendStatusAction()(dispatch), 5000);
}
} catch (err) {
dispatch(backendOffline());
}
};
}
调用代码的位置:
componentDidMount() {
const { loginActions, loadingAction } = this.props;
loadingAction(true);
loginActions.getBackendStatusAction();
}
componentDidUpdate(prevProps) {
const { loginError, backendStatus, loadingAction } = this.props;
const { showModal } = this.state;
if (prevProps.backendStatus !== backendStatus) {
loadingAction(!backendStatus);
}
if (loginError !== '' && loginError !== undefined && showModal === false) {
this.handleShowModal(loginError);
}
}
你能帮帮我吗?
答: 暂无答案
评论