首页 > 解决方案 > 为什么我的上下文状态没有在我的独特组件中呈现?

问题描述

我正在重定向我的唯一组件,我希望我的上下文 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>;
  }
}

当我记录它时,它会返回一个空数组,但是当我对另一个组件(如仪表板)进行类似的操作时,它会返回预期的数据。

标签: javascriptnode.jsreactjsuse-context

解决方案


推荐阅读