All Projects → mintothejoo → react-redux-webpack4-boilerplate

mintothejoo / react-redux-webpack4-boilerplate

Licence: other
boilerplate for react, redux, webpack4!

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-redux-webpack4-boilerplate

Vi-Ui
💙 A simple but consistent user interface made for Vue
Stars: ✭ 42 (+7.69%)
Mutual labels:  webpack4
easy-webpack-4
Webpack 4 simple example to quickly build a web application
Stars: ✭ 68 (+74.36%)
Mutual labels:  webpack4
webpack-starter
Simple webpack config with babel, scss, and lodash
Stars: ✭ 47 (+20.51%)
Mutual labels:  webpack4
webpack-demos
webpack小练习
Stars: ✭ 17 (-56.41%)
Mutual labels:  webpack4
webpack4-boilerplate
webpack4打包模板
Stars: ✭ 36 (-7.69%)
Mutual labels:  webpack4
eleventy bundler
NOT RECOMMENDED FOR USE; see README
Stars: ✭ 19 (-51.28%)
Mutual labels:  webpack4
eruda-webpack-plugin
A webpack plugin of eruda to help you develop mobile app
Stars: ✭ 56 (+43.59%)
Mutual labels:  webpack4
PERN-Advanced-Starter
Advanced PERN stack starter kit (PostgresSQL, Express, React, & Node), complete with ESLint, Webpack 4, Redux, React-Router, and Material-UI kit.
Stars: ✭ 51 (+30.77%)
Mutual labels:  webpack4
react-library-template
Jumpstart your team's shared react library
Stars: ✭ 26 (-33.33%)
Mutual labels:  webpack4
cruise
A Continuous Integration (CI) management system homework from Thought Works
Stars: ✭ 13 (-66.67%)
Mutual labels:  webpack4
boilerplate-react-redux-pwa
It's sample boilerplate with pwa + react + redux + redux-saga
Stars: ✭ 14 (-64.1%)
Mutual labels:  webpack4
bootpack
Create multi-page websites using bootstrap for development and webpack for task running.
Stars: ✭ 30 (-23.08%)
Mutual labels:  webpack4
webpack-alioss-upload-plugin
A flexible webpack plugin to upload files to aliyun oss, which supports multiple optional upload methods and parameters.
Stars: ✭ 14 (-64.1%)
Mutual labels:  webpack4
quickstart-miniprogram
🎉微信小程序webpack模板
Stars: ✭ 32 (-17.95%)
Mutual labels:  webpack4
webpack-boilerplate
Webpack 4 boilerplate with Babel, Bootstrap 4, jQuery and SCSS on board
Stars: ✭ 24 (-38.46%)
Mutual labels:  webpack4
webpack-boilerplate
Webpack 4 boilerplate (babel, eslint, prettier, jest, sass, postcss, hmr, browsersync)
Stars: ✭ 33 (-15.38%)
Mutual labels:  webpack4
nativescript-dev-webpack
A package to help with webpacking NativeScript apps.
Stars: ✭ 98 (+151.28%)
Mutual labels:  webpack4
cordova-plugin-webpack
Integrate webpack into your Cordova workflow.
Stars: ✭ 61 (+56.41%)
Mutual labels:  webpack4
webpack4-learn
📝 blog:https://itxiaohao.github.io/passages/webpack4-learn-introduction/
Stars: ✭ 70 (+79.49%)
Mutual labels:  webpack4
minimal-flask-react
🍸 A minimal modern setup for flask and react
Stars: ✭ 120 (+207.69%)
Mutual labels:  webpack4

This project was bootstrapped with Create React App.

Thanks To: Ali Alizada

I seriously looked everywhere for junior-senior levels to quickly start off a project with 
react, redux and the latest webpack. 
I know I wanted something like this so I can minimize the project setup time. 
I just decided to make it! It was all thanks to Ali! 

Don't forget to run npm install before npm start!

I bring you...

ReactDuxPack! (React + Redux + Webpack)

Folder Structure

The project looks like this:

my-app/
  src/
    components/
      Component1
        |-> Component1.js(or jsx)
        |-> style.scss
      index.js
    containers/
      Container1/
        |-> Container1.js 
      index.js
    redux/
      actions/
        |-> index.js
        |-> action1.js
      reducers/
        |-> index.js
        |-> reducer1.js
      store/
        |-> index.js
      types/
        |-> index.js
    router/
      Root.js
  public/
    |-> index.html
    |-> favicon.ico
  package.json
  node_modules/
  README.md
  -- setup files --
  .babelrc
  .eslintrc
  .prettierrc
  webpack.common / dev / prod.config

Why this structure?

You might be wondering why so many index.js!?

sample index.js code:

/*components/index.js*/

//from the component directory
import Button from './Button/Button.js';
export { Button };

If you have n amount of components, you import each into the index.js file and export the components accordingly... for example:

/*components/index.js*/

//n number of components
import Component1 from './Component1/Component1.js';
import Component2 from './Component2/Component2.js';
import Component3 from './Component3/Component3.js';
//...

export { Component1, Component2, Component3, ...}

To access these files from anywhere all you have to do is:

/*Container1.js*/
import { Component1, Component2, Component3 } from 'path/to/component/directory'
//You also don't have to import the index.js physically!!

instead of when you don't have index.js:

import { Component1 } from 'path/to/component1/directory';
import { Component2 } from 'path/to/component2/directory';
import { Component3 } from 'path/to/component3/directory';

Number of importing is too damn high!!

Creating Component with Action + Reducer

Redux is a hard concept to master, especially when there's too much to set up to get one state changed (e.g. button click).

To summarize. Redux is a HOC (Higher order Component) that takes care of all states in an app. Think of it as a parent component that has all possible states and the children (component) just pick and choose which state applies to them.

The pick and choose factor would be the mapStateToProps() function:

// connect to store
const mapStateToProps = state => ({
  buttonToggle: state.toggle,
});

The state variable in the mapStateToProps() function contains all of the states in the app. In this case we chose the toggle to be used into our component. We now assign it to a variable buttonToggle and will used like this.props.buttonToggle.

Process

If we go through this step by step, redux isn't as hard as you think!

  1. We create a Component directory, name it for whatever purpose you'll be using this for.

Actions + Reducer beauty

Now that we got the basic idea out of the way, let's move on to the concept of changing the state when something happens!

In a normal React App we would do something like :

this.setState({blah: blah});

to set the state. But this will only set the state for that component and the children associated with it ONLY if we gave this state to those children.

What Redux does is similar in that it changes the state but in a way where any component can dispatch an action to change the state of that app. Reducers would then listen for these actions and change according to the payload dispatched with the action.

To Summarize...

  • Action: Let's do this "Action!", Hey Reducer! Change this state! I'll give you the information to change it appropriately!

  • Reducer: Okay Action! I got your action details I'll change it accordingly!

Cheesy, but yeah.. That's the idea...

So how is it like in code?

Let us look at an example of a button toggle. We're going to set the state everytime a button is pressed!

Reducer

// 1
import * as types from '../types';

//2
const initialState = {
  isToggle: false,
  status: 'disabled',
};

//3
const toggle = (state = initialState, action) => {
  switch (action.type) {
    case types.BUTTON_ACTIVE:
      return {
        isToggle: action.payload,
        status: action.status,
      };

    case types.BUTTON_DISABLED:
      return {
        isToggle: action.payload,
        status: action.status,
      };
    default:
      return state;
  }
};

export default toggle;
  • //1 this is the type of action being sent, we preset the types of actions

  • //2 this is the initial state so when no actions are being called, we set it to these specific attributes

  • //3 this is the case statement to do certain state changing based off of the action type called... This is the part where the Reducer says: Okay Action! I got your action details I'll change it accordingly!

In this case our action details would be the action.payload and action.status these are completely up to what the dispatch sends, this will ultimately be what your states will be changed to!

Action

This is where things get tricky. Not becuase the code is hard to implement, but the fact that things are essentially blackboxed; you don't really know how this action is dispatched to the reducer. But we don't really need to know why as long as it works If you really want to know google.com is your best bet.

//1
import * as types from '../types';

//2
const toggle = (isToggle, status) => dispatch => {
  return dispatch({
    type: isToggle ? types.BUTTON_DISABLED : types.BUTTON_ACTIVE,
    payload: !isToggle,
    status: isToggle ? 'Active' : 'Disabled',
  });
};

export default toggle;
  • //1 Again, we get the type constants (the actions being called)

  • //2 This is where we dispatch the information. The important thing here is the type being dispatched. Based off of this dispatch, the Reducer does the sets the state.

Remember? we have the payload: and status:!! this is the action details I mentioned earlier!

Action Type Constants

export const BUTTON_ACTIVE = 'BUTTON_ACTIVE';
export const BUTTON_DISABLED = 'BUTTON_DISABLED';
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].