javascript - 为什么我的上下文状态没有在我的独特组件中呈现?
问题描述
我正在重定向我的唯一组件,我希望我的上下文 api 中的数据与我传递的参数匹配。
这是我的组件的代码;
export default function BasketballScoreboard() {
const dataContext = useContext(DataContext);
let { matchId } = useParams();
let nowMatch = dataContext.liveMatchList.filter(
(match) => match._id === matchId
);
if (!dataContext.isLoaded) {
return <Grid>Loading...</Grid>;
} else {
return <div>{nowMatch}</div>;
}
}
当我记录它时,它会返回一个空数组,但是当我对另一个组件(如仪表板)进行类似的操作时,它会返回预期的数据。
解决方案
推荐阅读
- html - CSS:相对于父级的固定位置?
- firebase - 优化数据以用于 Firebase Cloud Firestore 中的统计信息
- angular - Angular Routing:每当我刷新页面或手动输入特定 URL 时,Angular 都会重定向回父路由
- javascript - 将文件拖出浏览器
- firebase - Firebase FireStore 抽象功能不起作用
- python - 尝试在python中运行脚本时出现权限错误
- python-3.x - 查找 2 个 csv 文件之间的匹配项和分数
- css - 如何在反应上画五个开始
- r - Shiny 中动态调整大小的侧边栏面板和主面板
- python - 在python中查找和替换特定的json数据?