ReferenceError: anchorEl is not defined
ReferenceError: anchorEl is not defined
我还是新手 reactjs.I 尝试在我的代码中使用 popover 函数,但它说 anchorEl 没有声明,我不知道我应该在哪里声明 it.Here 是我的 code.I 如果您能帮助我,我将不胜感激。
class TropicalListNonMapped extends Component {
constructor(props) {
super(props);
this.state = {
anchorEl: null,
setanchorEl: null,
open: false,
data: [],
columns: [
[
{
dataField: "",
text: "Tindakan",
formatter: (cell, row) => (
<div
style={{ textAlign: "left" }}
className={this.props.classes.divAction}
>
<Button
onClick={(e) =>
this.setState({ open: true, anchorEl: e.currentTarget })
}
>
<Ionicon icon="md-more" />
</Button>
<Popover
open={open}
anchorEl={anchorEl}
onClose={() => this.setState({ open: false })}
anchorOrigin={{
vertical: "bottom",
horizontal: "center",
}}
transformOrigin={{
vertical: "top",
horizontal: "center",
}}
classes={{ paper: classNames(classes.popover) }}
>
</Popover>
</div>
在 Popover 组件中您需要修改您的道具:
anchorEl={this.state.anchorEl}
我还是新手 reactjs.I 尝试在我的代码中使用 popover 函数,但它说 anchorEl 没有声明,我不知道我应该在哪里声明 it.Here 是我的 code.I 如果您能帮助我,我将不胜感激。
class TropicalListNonMapped extends Component {
constructor(props) {
super(props);
this.state = {
anchorEl: null,
setanchorEl: null,
open: false,
data: [],
columns: [
[
{
dataField: "",
text: "Tindakan",
formatter: (cell, row) => (
<div
style={{ textAlign: "left" }}
className={this.props.classes.divAction}
>
<Button
onClick={(e) =>
this.setState({ open: true, anchorEl: e.currentTarget })
}
>
<Ionicon icon="md-more" />
</Button>
<Popover
open={open}
anchorEl={anchorEl}
onClose={() => this.setState({ open: false })}
anchorOrigin={{
vertical: "bottom",
horizontal: "center",
}}
transformOrigin={{
vertical: "top",
horizontal: "center",
}}
classes={{ paper: classNames(classes.popover) }}
>
</Popover>
</div>
在 Popover 组件中您需要修改您的道具:
anchorEl={this.state.anchorEl}