You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native特定流程Provider下List页面未接收到Props问题求助

问题原因及修复方案

1. 核心问题:路由属性未透传

React Navigation 会给所有路由配置对应的组件自动传入navigation、route等标准属性,但你当前的ListWithProvider作为路由直接关联组件,没有把收到的属性传递给内部的ListScreen,自然List页面无法获取对应props。
修正后的ListWithProvider写法:

export const ListWithProvider = (props) => {
    return <ListProvider>
        <ListScreen {...props}/>
    </ListProvider>
};

2. Context取值逻辑校验

如果你指的是无法获取Context内的状态和方法,请确认ListScreen中调用useContext时传入的是你自定义导出的List Context,示例写法:

import { Context as ListContext } from './你存放ListProvider的文件路径';

// ListScreen组件内部代码
const { state, setData } = useContext(ListContext);

3. 潜在问题补充

你当前的reducer没有处理setData对应的action,后续调用setData方法时状态不会更新,补充后的reducer参考:

const reducer = (state, action) => {
  switch (action.type) {
    case "setData":
      return { ...state, data: action.payload };
    default:
      return state;
  }
};

内容的提问来源于stack exchange,提问作者bm_fpl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 23:36:03