React组件根本没有使用{this.state.something}

时间:2015-08-23 01:04:36

标签: reactjs

状态正在被正确地声明,因为我在控制台时可以看到它。但是我的Jumbotron组件根本没有使用它。此外,它正在罚款,但{this.state.name}未显示。

var React = require('react');
var TeamStore = require('../stores/TeamStore');
import Jumbotron from 'react-bootstrap/lib/Jumbotron';

function getTeamState() {
    return { name: TeamStore.getSelected() };
}

console.log(TeamStore.getSelected());

var TeamApp = React.createClass({
    getInitialState: function() {
        return {getTeamState };
    },

    componentDidMount: function() {
        TeamStore.addChangeListener(this._onChange);
    },

    componentWillUnmount: function() {
        TeamStore.addChangeListener(this._onChange);
    },

    render: function() {

        return (
                <Jumbotron>
                    <h1 style={{"marginLeft": "270px"}}>{this.state.name}</h1>   
                 </Jumbotron>

            )
    },

    _onChange: function() {
        this.setState(getTeamState());
    }
});

module.exports = TeamApp;

1 个答案:

答案 0 :(得分:2)

您没有调用getTeamState,也不需要大括号。将其更改为:

getInitialState: function() {
    return getTeamState();
},