我有以下类片段:
constructor(props) {
super(props);
this.timeout = null;
}
search = (e) => {
clearTimeout(this.timeout);
this.timeout = setTimeout(
function(){ console.log(e.target); },
500
);
}
<input
type="text"
placeholder="Search by title or author"
onKeyPress={this.search} />
Run Code Online (Sandbox Code Playgroud)
我无法获得设置超时来打印事件中的值,是否有我应该做的事情,但我不是吗?
class MyDrawer extends Component {
const modalOpen = this.state;
render() {
return (
<div>
<Drawer
modal
open={this.state.modalOpen} // <-- this line show error [eslint] Must use destructuring state assignment (react/destructuring-assignment)
onClose={() => this.setState({ modalOpen: false })}
>
</Drawer>
</div>
);
}
}
export default MyDrawer;
Run Code Online (Sandbox Code Playgroud)
我尝试将行更改为,const { modalOpen } = this.state;但现在无法编译。
如何遵循规则并编辑代码以成功编译?