reactjs - Redux 和 Context API 在同一个 React Native 项目中一起使用
问题描述
我们可以在同一个 React Native 项目中使用 Redux 和 Context API 吗?如果我们一起使用它们有什么办法或有什么问题吗?
实际上,我想使用 Context API 实现身份验证,而对于其他状态管理,我想使用 Redux Toolkit。
解决方案
可以在项目中同时使用两者,但没有必要。你可以在 React中使用useReducer体验 redux 的简单部分。本文档对此进行了解释。它使用 Provider 来保持 contextAPI 和 redux 状态。在你的情况下,这可能就是这种情况。
<Provider store={reduxStore}>
<Context.Provider value={contextValue}
<App/>
</Context.Provider>
</Provider>
推荐阅读
- android - 如何使用时间戳获取 Cloud Firestore 中的日、月、年交易?
- spring-cloud-config - 在不同环境中使用 Hashicorp Vault 和 Spring Cloud
- c# - 如何从asp项目中引用类库
- flutter - 如何在 Flutter 中成功加载 webview 之前显示本地图像?
- php - 下载存储为 BLOB 的图像不起作用
- angular - NgRX 效果 - 类型 'Observable
' 不可分配给类型 'Observable ' - javascript - UnhandledPromiseRejectionWarning:node_modules\snapdragon-util\index.js:282 拒绝 react-native 中的未处理承诺
- ruby - 如何解决此问题,当我尝试在本地系统上进行身份验证时,它工作正常,但是当上传到 heroku 时,它返回错误 500?
- php - 如何修复 local.ERROR:使用 Laravel 加载 cafile 流失败
- c++ - SFML:dyld:库未加载错误,即使库路径已更新