How can I convert popover MATERIAL-UI functional component to class based component?

后端 未结 2 758
一个人的身影
一个人的身影 2021-01-06 11:11

I\'m trying to convert this functional component to class based component. I have tried for several hours but could not find where to place these const variable

2条回答
  •  情话喂你
    2021-01-06 12:14

        import React, { Component } from "react";
        import { createMuiTheme } from "@material-ui/core/styles";
        import Typography from "@material-ui/core/Typography";
        import Button from "@material-ui/core/Button";
        import Fade from "@material-ui/core/Fade";
        import Paper from "@material-ui/core/Paper";
        import Popper from "@material-ui/core/Popper";
        import { withStyles } from "@material-ui/styles";
    
        const theme = createMuiTheme({
          spacing: 4
        });
    
        const styles = {
          typography: {
            padding: theme.spacing(2)
          }
        };
        class SimplePopper extends Component {
          constructor(props) {
            super(props);
            this.state = { anchorEl: null, open: false };
          }
          flipOpen = () => this.setState({ ...this.state, open: !this.state.open });
          handleClick = event => {
            this.state.ancherEl
              ? this.setState({ anchorEl: null })
              : this.setState({ anchorEl: event.currentTarget });
            this.flipOpen();
          };
    
          render() {
            const open = this.state.anchorEl === null ? false : true;
            console.log(this.state.anchorEl);
            console.log(this.state.open);
            const id = this.state.open ? "simple-popper" : null;
            const { classes } = this.props;
            return (
              
    {({ TransitionProps }) => ( The content of the Popper. )}
    ); } } export default withStyles(styles)(SimplePopper);

提交回复
热议问题