5.0.2 • Published 2 years ago

@cra-express/redux-prefetcher v5.0.2

Weekly downloads
2
License
MIT
Repository
-
Last release
2 years ago

@cra-express/redux-prefetcher (deprecated)

DEPRECATED! No support/PR accepted for this package anymore. Alpha stage, API may change, don't use on production yet! Simple utility to map your routes and prefetch your data on server using Redux as store

Prerequisites

  • Redux
  • React Router with array config
  • Promise support

Start

npm i @cra-express/redux-prefetcher

Use

// server.js
import { getInitialData } from '@cra-express/redux-prefetcher'
import { renderToNodeStream } = from 'react-dom/server';

import routes from './my-app-routes'
import reducer from './my-app-reducer'

function handleUniversalRender (req, res) {
  const ctx = { req, res }
  const store = createStore(reducer);
  return getInitialData(ctx, store, routes)
    .then(() => {
      return renderToNodeStream(<App />)
    })
}
// MyView.js
import React, { Component } from 'react';
import { connect } from 'react-redux';

import { fetchTodo } from './my-todo-reducer';

class MyView extends Component {
  static loadData({ ctx, store, match }) {
    // ctx is object containing express req and res objects
    // store is redux store
    // match is router match information, you can get params here
    return store.dispatch(fetchTodo());
  }

  render() {
    return (
      <ul>
        {this.props.todo.data.map((t, i) => (
          <li key={i}>{t}</li>
        ))}
      </ul>
    );
  }
}

const mapStateToProps = (state) => ({
  todo: state.todo,
});

export default connect(mapStateToProps)(MyView);

License

MIT

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.3.2

4 years ago

4.3.1

5 years ago

4.3.0

5 years ago

4.2.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.1

5 years ago

4.0.0

6 years ago

4.0.0-alpha.3

6 years ago

4.0.0-alpha.2

6 years ago

4.0.0-alpha.1

6 years ago

4.0.0-alpha.0

6 years ago

4.0.0-9

6 years ago

4.0.0-8

6 years ago

4.0.0-7

6 years ago

4.0.0-6

6 years ago

4.0.0-5

6 years ago

4.0.0-4

6 years ago

4.0.0-3

6 years ago

4.0.0-2

6 years ago

4.0.0-1

6 years ago

4.0.0-0

6 years ago

2.2.4

6 years ago

2.2.4-0

6 years ago

2.2.3-0

6 years ago

2.2.2-0

6 years ago

2.2.1-0

6 years ago

2.2.0-0

6 years ago