Skip to content

Instantly share code, notes, and snippets.

@KevinVR
Created February 26, 2021 10:59
Show Gist options
  • Save KevinVR/5e78efbbed9f7cac0cb4ccdae7cde797 to your computer and use it in GitHub Desktop.
Save KevinVR/5e78efbbed9f7cac0cb4ccdae7cde797 to your computer and use it in GitHub Desktop.
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