Advertisement
Guest User

Hooks Ref

a guest
Oct 15th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import Header from './components/Header/Header';
  3. import Wheel from './components/Wheel/Wheel';
  4. import Buttons from './containers/Buttons/Buttons';
  5. import Footer from './components/Footer/Footer';
  6.  
  7. import './App.css';
  8.  
  9. class App extends Component {
  10.     constructor(props) {
  11.         super(props);
  12.  
  13.         this.state = {
  14.             spin: false,
  15.         };
  16.         this.spinWheel = this.spinWheel.bind(this);
  17.     }
  18.  
  19.     spinWheel = () => {
  20.         console.log("claim button clicked from <App/> Component");
  21.     };
  22.  
  23.     render() {
  24.         return (
  25.             <div className="App">
  26.                 <Header/>
  27.                 <Wheel/>
  28.                 <Buttons idSpin="spin-now" idClaim="claim-now" onClickClaim={() => this.spinWheel()} />
  29.                 <Footer/>
  30.             </div>
  31.         );
  32.     }
  33. }
  34.  
  35. export default App;
  36. ___________________________________________________________________________________________________________________________
  37. import React, { useState, useRef } from 'react';
  38. import SpinNowButton from '../../components/SpinNowButton/SpinNowButton';
  39. import ClaimNowButton from '../../components/ClaimNowButton/ClaimNowButton';
  40. import './Buttons.css';
  41.  
  42. const Buttons = (props) => {
  43.     const [showClaim, setShowClaim] = useState(false);
  44.     const clickEl = useRef(null);
  45.  
  46.     const handleClick = () => {
  47.         setShowClaim(!showClaim);
  48.         console.log("spin button clicked from <Button/> component");
  49.     };
  50.  
  51.     return(
  52.         <div className="both-buttons">
  53.             {showClaim ? null :
  54.                 <SpinNowButton onClick={() => handleClick()} ref={clickEl}/>
  55.             }
  56.  
  57.             <a href="#" onClick={props.onClickClaim}>
  58.                 {showClaim ? <ClaimNowButton /> : null}
  59.             </a>
  60.         </div>
  61.     );
  62. };
  63.  
  64. export default Buttons;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement