SHARE
TWEET

Untitled

a guest Sep 18th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from 'react';
  2.  
  3. function LoginButton(props) {
  4.   const { loggedIn, logIn, logOut } = props;
  5.  
  6.   return (
  7.     <>
  8.       <h3>{loggedIn ? 'Logged in' : 'Logged out'}</h3>
  9.       {
  10.         loggedIn
  11.           ? <button onClick={logOut}>Log out</button>
  12.           : <button onClick={logIn}>Log in</button>
  13.       }
  14.     </>        
  15.   );
  16. }
  17.  
  18. function App() {
  19.   const [ loggedIn, setLoggedIn ] = useState(false);
  20.  
  21.   return (
  22.     <LoginButton
  23.       loggedIn={loggedIn}
  24.       logIn={() => setLoggedIn(true)}
  25.       logOut={() => setLoggedIn(false)}
  26.     />
  27.   );
  28. }
  29.  
  30. export default App;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top