首页 > 解决方案 > React Native + Redux,使用 Express 后端设置

问题描述

我有一个将 redux 和 Axios 链接到 Express 后端的 ReactJS 网站。现在我必须从这个站点构建一个 React Native 应用程序,但我想使用相同的后端和数据库。网上发现React Native也可以使用Redux + Axios的功能!但是我可以使用我的 ReactJS 站点中的相同代码在我的应用程序上实现 Redux 功能吗?我发现 action/reducer 功能大部分都相同,但我可以使用像下面这样的 Redux 商店(我的 ReactJS 商店)在我的应用程序中创建商店吗?

import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';

const initialState = {};

const middleware = [thunk];

const store = createStore( rootReducer, initialState, compose(
    applyMiddleware(...middleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
));

export default store;

我必须遵循一些特定的规则,或者我需要在我的应用程序中实施一些设置以使其正常工作?

标签: javascriptreactjsreact-nativeredux

解决方案


推荐阅读