-5

Can you help me in changing this React stateless functional component to React class based component including the withRouter and history object as given?

const Menu = withRouter(({history}) => (
   <AppBar>

   </AppBar>
))
export default Menu
Emile Bergeron
  • 17,074
  • 5
  • 83
  • 129

2 Answers2

0

First, create your class component and then, create a constructor for the class. You can then define the states required inside the constructor, something like this-

export default class Menu extends React.Component {
 constructor(props) {
  super(props);
  this.state = {
   SomeVar: xyz,
   AnotherVar: undefined
  }
 }

 render() {
  return withRouter(({history}) => (
   <AppBar> </AppBar>
  ));
 }
}
Xvistasss
  • 66
  • 9
0
class Menu extends React.Component {
  render() {
    // you can use this.props.history anywhere in the class
    const { history } = this.props;
    return <AppBar>...</AppBar>
  }
}

export default withRouter(Menu);
helloitsjoe
  • 6,264
  • 3
  • 19
  • 32