我是React的新手,并试图制作一个简单的切换按钮来显示“ 0”或“ 1”,并且此数字必须为状态。终端给我,它编译成功,但是我一直在浏览器上出错。
TypeError: instance.render is not a function
finishClassComponent
node_modules/react-dom/cjs/react-dom.development.js:15319
15316 | } else {
15317 | {
15318 | setCurrentPhase('render');
> 15319 | nextChildren = instance.render();
| ^ 15320 |
15321 | if (debugRenderPhaseSideEffects || debugRenderPhaseSideEffectsForStrictMode && workInProgress.mode & StrictMode) {
15322 | instance.render();
这是我的代码
import React, { Component } from 'react';
import './App.css';
class App extends Component{
state={
orderStatus: 0
}
_orderStatusChanger = () => {
if (this.state.orderStatus === 0)
this.setState({
orderStatus: 1
})
else if (this.state.orderStatus === 1)
this.setState({
orderStatus: 0
})
}
reder(){
return(
<div>
<button onClick={this._orderStatusChanger}>Done{this.state.orderStatus}</button>
</div>
);
}
}
export default App;
答案 0 :(得分:2)
您有错字,请将reder()
更改为render()
。