我试图建立一个简单的计算器在反应使用组件。我想获取按钮的值并将其赋值为"currentItem",但是,我仍然得到错误“无法读取属性'setState‘of null”。这是密码。代码位于两个单独的jsx文件中。我真的很感谢你的帮助。
import React from 'react';
import NumbersComponent from './NumbersComponent.jsx';
import EquationComponent from './EquationComponent.jsx';
import
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleClick.bind(this);
}
handleClick() {
this.setState(prevState => ({
在进入事件处理部分之前,我一直在阅读文档并练习React文档中的一些内容。但是我不明白为什么在类组件中使用方法时我们必须绑定函数,有人能解释一下吗?例如:
class Toggle extends React.Component {
constructor(props) {
super(props);
this.state = {isToggleOn: true};
// This binding is necessary to make `this` work in the callback
this.handleClick = this.handleC
我想创建几个按钮,每次点击按钮的值将被添加
这就是我得到的
我做错了什么?什么是“对象对象”?
var Button = React.createClass({
localHandleClick: function(){
this.props.localHandleClick(this.props.increment); // get the increment value of each button
},
render: function(){
return(
<button onClick={this.props