SHARE
TWEET

Untitled

a guest Sep 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {useState} from 'react';
  2. import './App.css';
  3. import Conditional from './Conditional'
  4.  
  5. function App() {
  6.   const [isloggedIn,setIsLoggedIn] = useState(false)
  7.  
  8.   return(
  9.     <div>
  10.       <Conditional
  11.         status={isLoggedIn}
  12.         logIn={() => setIsLoggedIn(true)}
  13.         logOut={() => setIsLoggedIn(false)}
  14.       />
  15.     </div>
  16.   )
  17. }
  18.  
  19. export default App;
  20.  
  21. ________________________________
  22.  
  23. import React from 'react'
  24.  
  25. function Conditional(props) {
  26.     const { isLoggedIn, logIn, logOut } = props;
  27.  
  28.     return (
  29.         <div>
  30.             <h3>User status: {isLoggedIn ? "logged in" : "logged out"}</h3>
  31.             {
  32.                 isLoggedIn
  33.                     ? <button onClick={logOut}>Log out</button>
  34.                     : <button onClick={logIn}>Log in</button>
  35.             }
  36.         </div>
  37.     )
  38. }
  39.  
  40. export default Conditional
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top