我潜入了#react-redux-webpack'过去几天的世界,愿意尝试并创建登录模板。
我已经为快速视图更新注入了React Hot Loader,但是它只更新了未包含在' requireAuth'中的视图。部分。
我使用componentWillUpdate
和componentWillMount
来检测登录更改。所以我想知道React Hot Loader不能推动更改查看的原因是什么?因为我看到新数据(在IDE中更改/保存后)被拉到浏览器(在chrome网络检查器内)。
我会感激任何意见,因为我已经尝试了我的想法,但显然在redux世界中的两天还不足以快速计算出来))
这里需要身份验证'组件I是在教程的帮助下构建的,它的目的是为了它的目的:
import React, {Component} from 'react';
import {connect} from 'react-redux';
export default function (ComposedComponent) {
class Authentication extends Component {
// to receive access to ROUTER >>>
static contextTypes = {
router: React.PropTypes.object
};
componentWillMount() {
if (!this.props.authenticated) {
this.context.router.push('/');
alert("Please, SIGN IN to continue!");
}
};
componentWillUpdate(nextProps) {
if (!nextProps.authenticated) {
this.context.router.push('/');
alert("Come back soon :)");
}
}
render() {
return <ComposedComponent {...this.props} />
}
}
function mapStateToProps(state) {
return {authenticated: state.authenticated};
}
return connect(mapStateToProps)(Authentication);
}
查看包装资源&#39;组件,仅在登录后才可用:
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import {Router, Route, browserHistory} from 'react-router';
import requireAuth from './components/require_authentication';
import App from './components/app';
import Resources from './components/resources';
import reducers from './reducers';
const createStoreWithMiddleware = applyMiddleware()(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<Router history={browserHistory}>
<Route path="/" component={App}>
<Route path="resources" component={requireAuth(Resources)} />
</Route>
</Router>
</Provider>
, document.getElementById('root'));