在组件BlocklyDrawer
中,我试图更改code
父组件的状态。我在onChange()
事件中这样做,调用父组件的方法handleCodex
:
constructor(props) {
super(props);
this.state = {
code : "xxx",
};
this.handleCodex =
this.handleCodex.bind(this);
}
handleCodex(codex){
this.setState = ({
code: codex,
});
}
<BlocklyDrawer
tools={[INICIAR, MOVER, ATACAR]}
language = {Blockly.Javascript}
onChange={(code, workspace) => {
this.handleCodex(code);
}}
appearance={
{
categories: {
Agente: {
colour: '160'
},
},
}
}
>
虽然方法handleCodex
被执行,但code
状态并没有改变。