Created
November 3, 2019 01:26
-
-
Save Falconiere/86f9fd5c07254fe8e32a26bcd892ba50 to your computer and use it in GitHub Desktop.
A simple example with styled component
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' | |
import styled from 'styled-components' | |
// define styled component container | |
const SimpleComponentContainer = styled.div` | |
background-color: ${({ counter }) => counter > 10 ? 'red' : '#ddd' }; | |
` | |
export default function SimpleComponent(){ | |
const [counter, setCounter] = useState(0) | |
function handleOnClick(e){ | |
e.preventDefault() | |
setCounter(counter + 1) | |
} | |
return ( | |
<SimpleComponentContainer counter={counter}> | |
<h1>Counter: {counter} </h1> | |
<button onClick={handleOnClick}> Click me! </button> | |
</SimpleComponentContainer> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment