Add dependencies for API server:
npm install --save express body-parser lodashAdd start:api script to package.json to run API server:
{
"scripts": {
"build": "webpack --progress --colors --devtool source-map",
"build:watch": "webpack --watch --progress --colors --devtool source-map",
"eslint": "eslint .",
"lint": "npm run eslint",
"start:api": "node api-server.js",
"test": "npm run lint"
}
}Run API server:
npm run start:apiInstall whatwg-fetch & es6-promise libraries to polyfill Fetch API:
npm install --save whatwg-fetch es6-promiseInstall imports-loader & exports-loader to shim whatwg-fetch:
npm install --save-dev imports-loader exports-loaderUpdate webpack.config.js to shim fetch with imports-loader & exports-loader:
var webpack = require('webpack'),
path = require('path');
module.exports = {
entry: './src/index',
output: {
path: path.join(__dirname, 'src/dist'),
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js?$/,
loader: 'babel',
include: path.join(__dirname, 'src')
}
]
},
plugins: [
new webpack.ProvidePlugin({
'fetch': 'imports?this=>global!exports?global.fetch!whatwg-fetch'
})
]
};Rerun build:watch task:
npm run build:watch- Remove
emailsconstant inEmailApp, and replace with newemailsproperty on state that is set fromfetchcall to the API insidecomponentDidMount
Go to Step 4 - Long polling.