Good day! Maybe it's a bad question, but I can't find answer on it. I have React app, that oriented on json object, that dynamically changes from outside.
Code from NAV:
import MultiTable from '../multi';
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import Clock from '../clock'
let routes = [
{
exact: true,
path: '/Main',
main: () => <Main />
},
{
path: '/MultiTable',
main: () => <MultiClock />
}
];
function requireAll(requireContext) {
return requireContext.keys().map(requireContext);
}
const Configs = requireAll(require.context('../../../src/configs', false, /.json$/));
const Files = requireAll(require.context('../../../src/data', false, /.json$/));
const Multi = () => (
<MuiThemeProvider>
<MultiTable allData={[Files, Configs]}/>
</MuiThemeProvider>
);
const MultiClock = () => (
<div>
<Clock/>
<Multi/>
</div>
);
export default class Nav extends React.Component {
render() {
return (
<Router history='vah'>
<div style={{display: 'flex'}} ref="nav">
<Drawer
docked={true}
width={200}
>
<Link to='/Main' key="main">Main</Link>
<Link to='/MultiTable' key="multi">WithClock</Link>
</Drawer>
<div style={{flex: 1}}>
{routes.map((route, index) => (
<Route
key={index}
path={route.path}
exact={route.exact}
component={route.main}
/>
))}
</div>
</div>
</Router>
);
}
}
App forming tables from jsons and with hot-reloader on my dev-server I always see incoming information without full page refreshing. But when I adding new "static" component on Canvas - Clock - when something in Files or Configs changes - Clock refreshing too and blinking (showing that he is reloading).
In my logic: Clock doesn't cross with Files and Configs and must be not updated, when files changes.
Why this happening?
___UPD1: I want to understand why if changes some data in Multi, Element Clock is resreshing too and I don't need this, cause of blinking.
___UPD2:
webpack config:
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: [
'babel-polyfill',
'react-hot-loader/patch',
'webpack-dev-server/client?http://192.168.1.33:3000',
'webpack/hot/only-dev-server',
'./app/index.js'
],
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, '../dist'),
publicPath: '/static/'
},
module: {
rules: [
{test: /\.jsx?$/, use: ['babel-loader'], exclude: /node_modules/},
{test: /\.(less|css)$/, loader: 'style-loader!css-loader!less-loader'},
{test: /\.(xml)$/, loader: 'xml-loader'},
{test: /\.(svg|png|jpg|jpeg|gif|ico|eot|otf|ttf|woff|woff2)$/, loader: 'file-loader'}
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
],
devServer: {
host: '192.168.1.33',
port: 3000,
historyApiFallback: true,
hot: true,
compress: true
}
};
in .babelrc:
{
"presets": [
["es2015", {"modules": false}],
"stage-2",
"react"
],
"plugins": [
"react-hot-loader/babel"
]
}
Main entry /app/index.js:
import React from 'react';
import ReactDOM from 'react-dom'
import {AppContainer} from 'react-hot-loader'
import injectTapEventPlugin from 'react-tap-event-plugin';
injectTapEventPlugin();
import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider';
import Nav from './navigation/nav';
import './index.less';
const rootEl = document.getElementById('root');
const render = Component => {
ReactDOM.render(
<AppContainer>
<MuiThemeProvider>
<Component />
</MuiThemeProvider>
</AppContainer>,
rootEl
)
};
render(Nav);
if (module.hot) {
module.hot.accept('./navigation/nav', () => {
render(Nav)
})
}
Maybe I really done some errors in configs and don't fully understanding of how this technologies must work. hot-loader+webpack+router