Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cra-express/redux-prefetcher

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cra-express/redux-prefetcher

Redux Prefetcher for prefetching on server

  • 2.2.4-0
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@cra-express/redux-prefetcher

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

FAQs

Package last updated on 21 May 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc