【发布时间】:2021-06-19 12:42:29
【问题描述】:
我仍在研究我的反应技能,并且在重定向回我所在的当前“页面”(组件/控件)时遇到了困难。下面是我在 app.js 文件中的一些示例代码,然后是我在“PageTwo.js”文件中的 sn-p。目前,当我单击复选框图标时,页面似乎会重定向,但我的表格数据都没有显示,或者说它可能是我的表格控件没有重新加载。任何帮助将不胜感激。
app.js
<Switch>
<Route path="/" exact component={SignUp} />
<Route path="/PageTwo" exact component={PageTwo} />
<Route path="/PageThree/:id" exact component={PageThree} />
</Switch>
PageTwo.js
.
.
.
const myRedirect = (stdId) => {
history.push('/PageTwo/' + stdId);
}
.
.
.
useEffect(() => {
let ref = Firebase.database().ref('/studentTime');
var refQuery = ref.orderByChild("TimeOut").equalTo("");
refQuery.on("value", studentTimeLog => {
theTimeLogList = O2A(studentTimeLog);
getTheTimeLog(theTimeLogList);
});
let userRef = Firebase.database().ref('/users');
var userQuery = userRef.orderByChild("Email").equalTo(authContext.userEmail);
//console.log(userQuery);
userQuery.once("value", function (snapshot) {
snapshot.forEach(function (child) {
if (child.val().Role === "ADMIN") {
authContext.isAdmin = true;
console.log(authContext.isAdmin);
}
});
});
}, []);
.
.
.
<TableCell align="center">
<CheckIcon onClick={() =>myRedirect(row.StudentId)}/>
</TableCell>
</TableRow>
【问题讨论】:
标签: reactjs react-router react-hooks