zoukankan      html  css  js  c++  java
  • react: next-redux-saga

    instead of using the Provider component, you can use the withRedux higher order component to inject the store initialization functionality.

    import withRedux from 'next-redux-wrapper';
    import initializeStore from './path/to/store';
    
    const HomePage = () =>
      <div>
        That's the home page.
      </div>
    
    export default withRedux(initializeStore)(HomePage);

    Basically, in a server-side rendered React application with Next.js, you can exchange the Providercomponent from react-redux with withRedux from next-redux-wrapper. You can use it for every entry point in your pages/ directory.

    In your child components, you can still use the connect higher order component from react-redux to make your Redux store accessible with mapStateToProps and mapDispatchToProps. It works the same as before.

    Redux Saga + Next.js

    Last but not least, I had the requirement to use Redux Saga for asynchronous Redux actions in my Next.js application. The basic Redux Saga middleware lookup when creating a Redux store looks similar to this

    import createSagaMiddleware from 'redux-saga';
    
    import rootSaga from 'path/to/combined/sagas';
    import rootReducer from 'path/to/combined/reducers';
    
    const saga = createSagaMiddleware();
    
    const initializeStore = initialState => {
      const store = createStore(
        rootReducer,
        initialState,
        applyMiddleware(saga)
      );
    
      saga.run(rootSaga);
    
      return store;
    };
    
    export default initializeStore;
  • 相关阅读:
    日志模块
    DDT数据驱动
    unittest测试框架
    vim编辑器
    文件夹的管理
    文件内容查看(如查看日志)
    文件的移动和拷贝
    文件的增删改查
    linux基本命令
    测试5--模拟一个在控制台不断按时分秒打印的电子表
  • 原文地址:https://www.cnblogs.com/Nyan-Workflow-FC/p/9378438.html
Copyright © 2011-2022 走看看