GithubHelp home page GithubHelp logo

vidup / react-redux-babel-webpack-hmr-starter-kit Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 10 KB

A project starter with React, Redux, Babel (set to stage-2, which includes Async/Await), built by webpack with Hot Module Replacement. Use for development only.

JavaScript 91.43% CSS 3.63% HTML 4.94%

react-redux-babel-webpack-hmr-starter-kit's Introduction

Modern React project starter Kit

This is a first version a of starter kit for modern React & Redux applications. It uses webpack to bundle. For now, it's only for development use.

To use it, just clone the repository and use yarn start (or npm if you still use it).

Main features :

  • React, Redux, Immutable.
  • Webpack bundling, with Hot Module Replacement, through an express server, thanks to the webpack-dev-middleware.
  • Contains a preset browserHistory object (based on the history package), which you can use to handle your user history.
browserHistory.push({ pathname: '/newPath' });

which allows the user to come back to the page he previously in, or :

browserHistory.replace({ pathname: '/newPath' });

which replace the current page by the new one, preventing the user to come back, or :

browserHistory.push({
  pathname: '/newPath',
  search: '?the=query',
})

The search property allows you to add a queryString to the new page.

  • A routing also present, which allows you to add containers to specific routes.
import React from 'react';
import { Route, IndexRoute } from 'react-router';
import App from './containers/App';
import Index from './containers/Index';
import Map from './containers/Map';

<Route path="/" component={App}>
  <IndexRoute component={Index} />
  <Route component={Map} />
</Route>
  • Redux stores are pre-configured to be combined, following the official documentation.

  • Actions are transformed into asynchronous functions by the redux-thunk middleware. It looks like this.

import services from '../services';

const fetchData = () => async (dispatch) => {
  dispatch({ type: 'BOOKING_DATA_PENDING' });

  let data;
  try {
    data = await services.data.fetch();
  } catch (error) {
    dispatch({ type: 'BOOKING_FETCH_FULFILLED', data: null, error });
    return;
  }
  dispatch({ type: 'BOOKING_FETCH_FULFILLED', data, error: null });
};

The same BOOKING_FETCH_FULFILLED action is emitted whether or not the fetching (from a service file dedicated to it) actually worked. The only difference is in the data and error passed within it. You need to take this into consideration in the reducer.

  • Redux & React linking packages are shipped.
  • Class properties are allowed, which means, among other things, that you can add static properties to your React (and plain JS) classes.
import React, {Component, PropTypes} from 'react';
import { connect } from 'react-redux';

class ReactContainer extends Component {
  static propTypes = {
    data: PropTypes.object.isRequired,
  };

  render() {
    return (
      <div>

      </div>
    );
  }
}

const mapStateToProps = ({ stuffReducer, userReducer, etc... }) => ({
  data: stuffReducer.get('data'),
});

export default connect(mapStateToProps)(ReactContainer);

TODO

  • Better README
  • Add Tests to the starter kit.

react-redux-babel-webpack-hmr-starter-kit's People

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.