Advertisement
cunha1

Untitled

Jan 31st, 2020
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2.  
  3. class Element extends React.Component {
  4.     constructor(props) {
  5.         super(props);
  6.         this.state = {menuOpen:false};
  7.     }
  8.     render() {
  9.         return (
  10.             <>
  11.                 <h1 onClick={()=>this.toggleMenuOpen()} style={{"cursor":"pointer"}}>Klikni me</h1>
  12.                 {this.state.menuOpen?<Menu text="Debeli daro testira debeli meni" />:""}
  13.             </>
  14.         );
  15.     }
  16.     toggleMenuOpen() {
  17.         this.setState(prevstate => ({
  18.             menuOpen:!prevstate.menuOpen
  19.         }));
  20.     }
  21. }
  22.  
  23. class Menu extends React.Component {
  24.     constructor(props) {
  25.         super(props);
  26.     }
  27.     render() {
  28.         return (
  29.             <div className="menu" style={{"backgroundColor": "#333", "width": "100px", "height": "100px"}}>
  30.                 {this.props.text}
  31.             </div>
  32.         );
  33.     }
  34. }
  35.  
  36. export default Element;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement