如何在Reaction中访问DOM元素?Reaction中document.getElementById()的等价键是什么?
var Progressbar = React.createClass({ getInitialState: function () { return { completed: this.props.completed }; }, addPrecent: function (value) { this.props.completed += value; this.setState({ completed: this.props.completed }); }, render: function () { var completed = this.props.completed; if (completed < 0) { completed = 0 }; return (...); }
var App = React.createClass({ getInitialState: function () { return { baction: 'Progress1' }; }, handleChange: function (e) { var value = e.target.value; console.log(value); this.setState({ baction: value }); }, handleClick10: function (e) { console.log('You clicked: ', this.state.baction); document.getElementById(this.state.baction).addPrecent(10); },
You clicked: Progress1 TypeError: document.getElementById(...) is null
Cats萌萌