reactjs - 在使用提供者包裹的屏幕中未收到道具
问题描述
我是新手,所以请帮忙。
我不想将整个应用程序包装在上下文提供程序周围,而是只想包装特定流程 App -> Dashboard -> Provider{ List -> Details}
我已经让它在流程中工作,但现在这里的问题是我没有在列表屏幕中获得任何道具,有人可以检查并提供帮助吗?
创建数据上下文模板 ::
export default (reducer, actions, initialState) => {
const Context = React.createContext();
const Provider = ({ children }) => {
const [state, dispatch] = useReducer(reducer, initialState);
const boundActions = {};
for (let key in actions) {
boundActions[key] = actions[key](dispatch);
}
return (
<Context.Provider value={{ state, ...boundActions }}>
{children}
</Context.Provider>
);
};
return { Context, Provider };
};
导航::
<NavigationContainer>
<Stack.Navigator initialRouteName="Dashboard" screenOptions={{
headerBackTitleVisible: false
}}>
<Stack.Screen name="Dashboard" component={DashboardScreen} />
<Stack.Screen name="NewsList" component={ListWithProvider} />
</Stack.Navigator>
</NavigationContainer>
ListWithProvider::
export const ListWithProvider = () => {
return <ListProvider>
<ListScreen/>
</ListProvider>
};
列表提供者::
const reducer = (state, action) => {
switch (action.type) {
default:
return state;
}
};
const setData = (dispatch) => {
return (source) =>{
dispatch({type:"setData", payload: source});
}
}
export const { Context, Provider } = CreateDataContext(
reducer,
{ setData },
{loading: false, data: null, error: null, filter: "all"}
);
解决方案
推荐阅读
- python-3.x - 为什么(miniconda)pip 安装在 .local
- firebase - 使用 BusBoy for firebase 的 FormData 在服务中有效,但在部署中无效
- html - 可以只导出数据表列的一部分值吗?
- apache-spark - 我创建了一个文件来访问所有全局变量。我无法访问 pyspark-sql 查询中定义的 UDF 中的全局变量
- android - 具有两种自定义颜色的 ActonBar
- html - 在响应式导航中,第一个元素不会显示在 img 下方
- python - 忽略第三方模块中的 logging.basicConfig
- powershell - Powershell循环遍历文件夹移动文件,如果不存在则创建目录
- android - 影响应用性能的多个 NetworkCallback 事件 (onAvailable)
- cmake - 使用 vcpkg 时如何包含 OpenCV 的 cv::VideoWriter?