Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement