Redux是一个非常流行的JavaScript状态管理库,它允许用户管理应用中的状态,从而使得代码变得更加可测试和维护。以下是在Linux上使用ksh以及AIX/Solaris/HP-UX上安装的ksh进行Redux的安装和使用的通用步骤:
npm install --save-dev redux
npm install --save-dev @reduxjs/devtools
npm install --save-dev react-router-dom
App.js
中引入Redux DevTools:
导入Redux DevTools并将其添加到渲染函数中,例如:
import React from 'react';
import { createStore, compose } from 'redux';
import { Provider } from 'react-redux';
import { configureStore, history } from 'react-router-dom';
import ReduxDevTools from '@reduxjs/devtools';
import createReduxStore from './redux/store';
import reducers from './redux/reducers';
const configureStoreWithDevTools = configureStore.composeWithDevTools(
ReduxDevTools.instrument()
);
const store = configureStoreWithDevTools(createReduxStore)(
reducers
);
if (process.env.NODE_ENV === 'development') {
configureStoreWithDevTools(createReduxStore, history)(
reducers
);
}
export default function MyApp() {
const history = useBasename(history, fromParams());
return (
<Provider store={store}>
<Router history={history} basename="/">
<Switch>
{/* Your code goes here */}
</Switch>
</Router>
<ReduxDevTools />
</Provider>
);
};
现在你有一个可以使用Redux应用程序了。
sudo ksh gem install Redux
sudo ksh gem install Redux/devtools
sudo ksh gem install react-router-dom
import React from 'react';
import { createStore, compose } from 'redux';
import { Provider } from 'react-redux';
import { configureStore, history } from 'react-router-dom';
import ReduxDevTools from '@reduxjs/devtools';
import createReduxStore from './redux/store';
import reducers from './redux/reducers';
const configureStoreWithDevTools = configureStore.composeWithDevTools(
ReduxDevTools.instrument()
);
const store = configureStoreWithDevTools(createReduxStore)(
reducers
);
if (process.env.NODE_ENV === 'development') {
configureStoreWithDevTools(createReduxStore, history)(
reducers
);
}
export default function MyApp() {
const history = useBasename(history, fromParams());
return (
<Provider store={store}>
<Router history={history} basename="/">
<Switch>
{/* Your code goes here */}
</Switch>
</Router>
<ReduxDevTools />
</Provider>
);
};
现在你有一个可以使用Redux的应用程序了。
领取专属 10元无门槛券
手把手带您无忧上云