diff --git a/.eslintrc.yml b/.eslintrc.yml index 3baeae1..94aadd5 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -4,6 +4,8 @@ env: extends: - 'airbnb' parser: 'babel-eslint' +plugins: + - 'react-hooks' rules: react/jsx-filename-extension: - error @@ -24,3 +26,4 @@ rules: - 'Link' specialLink: - 'to' + react-hooks/rules-of-hooks: 'error' diff --git a/.travis.yml b/.travis.yml index 15a95fd..55f2bef 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: node_js node_js: - 8 - - 6 install: - yarn diff --git a/README.md b/README.md index 8750142..6ae18a8 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ This boilerplate would help you build a react/redux/react-router isomorphic/univ - manage your style in [CSS Modules](https://github.com/css-modules/css-modules) way. - babel v7 - optimize bundle size by implementing [tree shaking](https://webpack.js.org/guides/tree-shaking/) +- react hooks!(I hate OO components) ## Concept ### Getting Started diff --git a/babel.config.js b/babel.config.js index 5ebf461..a8b5118 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,5 +1,5 @@ module.exports = function babelConfig(api) { - api.cache(false); + api.cache(true); // set to other value if we handle env variable here return { presets: [ '@babel/react', diff --git a/package.json b/package.json index 8d83ec5..4953230 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,10 @@ { "name": "react-isomorphic-boilerplate", - "version": "0.7.1", + "version": "0.7.2", "main": "src/server/index.js", "license": "MIT", "engines": { - "node": "^6.14.0 || ^8.10.0 || >=9.10.0" + "node": "^8.10.0 || >=9.10.0" }, "scripts": { "start": "DEBUG=*,-nodemon*,-express*,-send,-babel*,-eslint*,-css-modules* NODE_ENV=hot npx babel-node --inspect src/server/hot/index.js", @@ -23,6 +23,7 @@ "@babel/node": "^7.0.0", "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/plugin-transform-runtime": "^7.1.0", + "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.1.5", "@babel/preset-react": "^7.0.0", "@babel/register": "^7.0.0", @@ -45,6 +46,7 @@ "eslint-plugin-import": "^2.14.0", "eslint-plugin-jsx-a11y": "^6.1.1", "eslint-plugin-react": "^7.11.1", + "eslint-plugin-react-hooks": "^0.0.0", "file-loader": "^2.0.0", "ignore-styles": "^5.0.1", "mini-css-extract-plugin": "^0.4.4", @@ -84,11 +86,11 @@ "lodash": "^4.17.4", "normalizr": "^3.2.4", "prop-types": "^15.6.0", - "react": "^16.4.1", - "react-dom": "^16.4.1", + "react": "^16.7.0-alpha.2", + "react-dom": "^16.7.0-alpha.2", "react-helmet": "^5.2.0", - "react-hot-loader": "^4.3.12", - "react-redux": "^5.0.6", + "react-hot-loader": "^4.5.1", + "react-redux": "^6.0.0-beta.2", "react-router": "^4.3.1", "react-router-dom": "^4.3.1", "redux": "^4.0.0", @@ -124,6 +126,7 @@ ], "require": [ "@babel/register", + "@babel/polyfill", "ignore-styles", "css-modules-require-hook/preset", "./src/enzymeSetup.js" @@ -131,7 +134,8 @@ }, "nyc": { "require": [ - "@babel/register" + "@babel/register", + "@babel/polyfill" ], "sourceMap": false, "instrument": false diff --git a/src/actions/index.js b/src/actions/index.js index 7ca8cc6..21a490b 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -11,9 +11,11 @@ export function accumulateCount() { } export function dummy() { - return { - type: 'DUMMY_ACTION', - }; + return async dispatch => new Promise(() => setTimeout(() => { + dispatch({ + type: 'DUMMY_ACTION', + }); + }, 1000)); } export function updateMe(me) { diff --git a/src/containers/Home/FormPostTotalCount.js b/src/containers/Home/FormPostTotalCount.js new file mode 100644 index 0000000..bde78ee --- /dev/null +++ b/src/containers/Home/FormPostTotalCount.js @@ -0,0 +1,30 @@ +import React/* , { useEffect } */ from 'react'; +import { useRedux } from '../../hooks/useRedux'; +import useDummy from '../../hooks/useDummy'; + +import style from './style.scss'; // eslint-disable-line no-unused-vars + +export default function FormPostTotalCount() { + const [state] = useRedux(); + const [dummyTimes, triggerDummy] = useDummy(); + + return ( +
+ + this component uses react hook + +
+ Total  + {state.pages.home.posts.length} +  Posts +
+
+ {dummyTimes} +  times dummy +
+ +
+ ); +} diff --git a/src/containers/Home/index.js b/src/containers/Home/index.js index 714b57b..b3a59af 100644 --- a/src/containers/Home/index.js +++ b/src/containers/Home/index.js @@ -5,6 +5,7 @@ import { connect } from 'react-redux'; import { get as _get } from 'lodash'; import { dummy as dummyAct, fetchPosts as fetchPostsAction } from '../../actions'; import FormPostComponent from './FormPost'; +import FormPostTotalCount from './FormPostTotalCount'; import PostlistComponent from './Postlist'; import stdout from '../../stdout'; import style from './style.scss'; // eslint-disable-line no-unused-vars @@ -45,6 +46,7 @@ export class Home extends React.Component { +