class YourClass extends React.Component {
constructor(props) {
super(props);
this.state = {
sidebar: 0 // this is a good place to set Initial value
};
}
showSidebar = () => { // This is a method of the class, similar to your arrow f
this.setState({ sidebar: !this.state.sidebar });
};
render() {
return // render your things here, similar to what you "return" in hooks
// You can use your this.state.sidebar value here, similar to "sidebar"
}
}
1条答案
按热度按时间osh3o9ms1#
你应该研究一下Class component是如何工作的,只要花10分钟,我相信如果你有关于钩子的知识,你会很快习惯它。
这里是您所要求的示例,只是为了让您开始;