Learn the fundamentals of React, including simple and class components, state, props, and submitting form data.
Conditional rendering
<div id="root"></div> |
function UserGreeting(props) { | |
return <h1>Welcome back!</h1>; | |
} | |
function GuestGreeting(props) { | |
return <h1>Please sign in.</h1>; | |
} | |
function Greeting(props) { | |
const isLoggedIn = props.isLoggedIn; | |
if (isLoggedIn) { | |
return <UserGreeting />; | |
} | |
return <GuestGreeting />; | |
} | |
ReactDOM.render( | |
<Greeting isLoggedIn={false} />, | |
document.getElementById("root") | |
); |
<script src="https://unpkg.com/react/umd/react.development.js"></script> | |
<script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script> |