FluxMixin错误" Uncaught TypeError:无法读取属性'存储'未定义"升级到React 0.14.x

时间:2015-10-30 17:04:02

标签: reactjs react-router flux

我试图从0.13升级到React 0.14。我收到错误"未捕获的TypeError:无法读取属性'存储'未定义"在我的Application.jsx组件中(参见下面的代码)。

基本上我在Application.jsx中未定义flux。我无法弄清楚我做错了什么,但我怀疑问题是我在<Router/>中定义app.jsx的方式,而不是通过某些财产或其他,使用错误的语法等,或已更改/弃用FluxMixin并且没有人更新文档?

请帮忙。

//----------app.jsx---------- This is the entry app point
'use strict';
import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route, IndexRoute} from 'react-router';
import Fluxxor from 'fluxxor';
import Application from './components/Application';

let stores = {
    UserStore: new UserStore(),
};

let actions = {
    user: require('./actions/UserActionCreators'),
};

let flux = new Fluxxor.Flux(stores, actions);
let createBrowserHistory = require('history/lib/createBrowserHistory');

let batchedUpdates = require('react/lib/ReactUpdates').batchedUpdates;
let oldDispatch = flux.dispatcher.dispatch.bind(flux.dispatcher);
flux.dispatcher.dispatch = function(action) {
    batchedUpdates(function() {
        oldDispatch(action);
    });
};
const routes = (
    <Route flux={flux} component={Application}/>
);
let history = createBrowserHistory();
ReactDOM.render(<Router history={history} routes={routes}/>, document.getElementById('content'));

//----------Application.jsx----------
'use strict';

import React from 'react';
import ReactDOM from 'react-dom';
import {Router, History} from 'react-router';
import Fluxxor from 'fluxxor';
const FluxMixin = Fluxxor.FluxMixin(React);
const StoreWatchMixin = Fluxxor.StoreWatchMixin;

const Application = React.createClass({
    mixins: [History, FluxMixin, StoreWatchMixin('UserStore')],
    // Required by StoreWatchMixin
    getStateFromFlux() {
        return {
            // Getting an error here "Uncaught TypeError: Cannot read property 'store' of undefined":
            user: this.getFlux().store('UserStore').getState()
        };
    },
    render() {
        return (
            <div>Work already you bollox!!!</div>
        );
    }
});

module.exports = Application;

0 个答案:

没有答案