3.0.2 • Published 4 years ago

@feizheng/next-react-redux v3.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

next-react-redux

React redux enhanced version based on next toolkit.

installation

npm i @feizheng/next-react-redux

options

nametypevaluedescription
nx.$memoryObject{}Application memory data storage
nx.$localObjectnullApplication localStoarage
nx.$sessionObject{}Application sessionStoreage
nx.$globalObject{}Application set/get global properties
nx.$appObject{}Application instance

get-started

  • HTML
<main id="app"></main>
  • index.js
import  { $api, $config, $store } from '#';
import { HashRouter as Router, Switch } from 'react-router-dom';
import { renderRoutes } from 'react-router-config';
import routes from './routes';
import { ReduxAppBase, ReduxBoot, reduxRender } from '@feizheng/next-react-redux';
import 'assets/styles/index.scss';

// DO NOT USE `@hotable`
@reduxRender('app', { prefix: 'react-spa', loadable: false })
export default class extends ReduxAppBase {
  static initialState(inStore) {
    const { login } = inStore.local;
    return {
      local: {
        login: login || null
      },
      memory: {
        modalUser: false,
        modalUserQuery: false
      }
    };
  }

  componentDidMount() {
    const { history } = this.root;
    nx.$global = { 'abc.test': 123 };
    nx.$memory = { history };
  }

  eventBus(inName, inData) {
    console.log('*, I am - global event bus center:->', inName, inData);
  }

  render() {
    return (
      <Router ref={(root) => (this.root = root)}>
        <Switch>{renderRoutes(routes)}</Switch>
      </Router>
    );
  }
}