我只是在写文本输入,onChange如果我打电话setState,那么React会重新渲染我的UI。问题是文本输入始终会失去焦点,因此我需要再次针对每个字母:D。
var EditorContainer = React.createClass({
    componentDidMount: function () {
        $(this.getDOMNode()).slimScroll({height: this.props.height, distance: '4px', size: '8px'});
    },
    componentDidUpdate: function () {
        console.log("zde");
        $(this.getDOMNode()).slimScroll({destroy: true}).slimScroll({height: 'auto', distance: '4px', size: '8px'});
    },
    changeSelectedComponentName: function (e) {
        //this.props.editor.selectedComponent.name = $(e.target).val();
        this.props.editor.forceUpdate();
    },
    render: function () {
        var style = {
            height: this.props.height + 'px'
        };
        return (
            <div className="container" style={style}>
                <div className="row">
                    <div className="col-xs-6">
                    {this.props.selected ? <h3>{this.props.selected.name}</h3> : ''}
                    {this.props.selected ? <input type="text" value={this.props.selected.name} onChange={this.changeSelectedComponentName} /> : ''}
                    </div>
                    <div className="col-xs-6">
                        <ComponentTree editor={this.props.editor} components={this.props.components}/>
                    </div>
                </div>
            </div>
        );
    }
});


我遇到了这个问题,结果却是我正在使用功能组件并与父组件的状态链接。如果我改用类组件,问题就消失了。希望在使用功能组件时可以解决此问题,因为对于简单的项目渲染器等而言,它要方便得多。