Created
February 26, 2021 10:59
-
-
Save KevinVR/5e78efbbed9f7cac0cb4ccdae7cde797 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState} from 'react'; | |
function MyStateComponent = ({ showHeading }) => { | |
// useState always returns two items: | |
// 1. headingText - the value of our state variable | |
// 2. setHeadingText - the setter for our state variable | |
const [headingText, setHeadingText] = useState('Default Heading'); | |
// Now, update the state depending on some condition! | |
if (showHeading) { | |
setHeadingText('Show Heading is True!'); | |
} | |
return showHeading ? <h1>{headingText}</h1> : null; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment