Not using a big react boilerplate, implement routing, web serving, redux-pattern, code-splitting, etc by myself based on start-react-app
inspired by react-boilerplate
continuously adding new features and packages
- 2018-02-28 : first start of this project with
start-react-app
package - 2018-03-01 :
react-router
/react-router-dom
- 2018-03-14 :
redux
/react-redux
andimmutable
- 2018-03-14 : use
prop-types
for type checking - 2018-03-14 : use
react-loadable
for simple code-splitting - 2018-03-15 : use
reselect
for constructing structured selector
- 2018-xx-xx :
redux-saga
(redux middleware who manage side-effects) - 2018-xx-xx :
styled-component
- 2018-xx-xx :
react-injectable-reducer
npm install -g create-react-app
create-react-app myapp
cd ./myapp
npm start
npm build
npm install -g serve
serve -s ./build
yarn
: package managerreact-router-dom
: router js package using in client browsercross-env
: setting environment variableNODE_PATH
in various OS .NODE_PATH
is used loading files along to absolute path.query-string
: for url query parsing in routerhostname/user/?id=1/?name=jayne
npm install -g yarn
yarn add react-router-dom
yarn add cross-env --dev
yarn add query-string
"scripts": {
"start": "cross-env NODE_PATH=src && react-scripts start",
"build": "cross-env NODE_PATH=src && react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
},
react-router
package provides core functions for routing in react.
Both react-router-dom
and react-router-native
re-export react-router
, to be more fit to each environment (browser DOM and native app).
For browser based project, there are two types of router, <BrowserRouter>
and <HashRouter>
.
When you can handle dynamic request with application server, it is always recommended to use <BrouserRouter>
.
If you have the server which can only serve static files, then you may use <HashRouter>
.
redux
is state managing library. We can use redux
with react by using react-redux
package.
- immutable
- redux
- react-redux
- redux-immutable
immutable
official doc : https://facebook.github.io/immutable-js/redux-immutable
gitgub doc : https://github.com/gajus/redux-immutable
- npm info : https://www.npmjs.com/package/prop-types
- react doc : https://reactjs.org/docs/typechecking-with-proptypes.html
npm install --save prop-types
import PropTypes from 'prop-types'; // ES6
var PropTypes = require('prop-types'); // ES5 with npm
react-loadable
is a yarn package to make code-splitting super simple
yarn add react-loadable
This package make you available to do component-based code splitting. The only thing you have to do is wrap your component (especially container component) with Loadable, like the code below.
import Loadable from 'react-loadable';
import Loading from './my-loading-component';
const LoadableComponent = Loadable({
loader: () => import('./my-component'),
loading: Loading,
});
export default class App extends React.Component {
render() {
return <LoadableComponent/>;
}
}
- github doc : https://github.com/reactjs/reselect
npm install --save reselect
- easily wrap a selector and make more specific selector
const getTodo = (state)=> state.get(todo) ;
const getFilter = createSelector(
getTodo,
(todo)=>todo.filter
);
- easily wrap two or more selectors and make some new selection
const getFilteredList = createSelector(
[getList, getFilter],
(list, filter)=> {
switch(filter) {
case 'ALL' :
return list;
default :
return list;
}
}
) ;
make final composed selector
const selector = createStructuredSelector({
filteredList: getFilteredList,
});
//same code
const selector = createSelector(
getFilteredList,
(result) => {filteredList : result }
);