Skip to content

Instantly share code, notes, and snippets.

@Falconiere
Created November 3, 2019 01:26
Show Gist options
  • Save Falconiere/86f9fd5c07254fe8e32a26bcd892ba50 to your computer and use it in GitHub Desktop.
Save Falconiere/86f9fd5c07254fe8e32a26bcd892ba50 to your computer and use it in GitHub Desktop.
A simple example with styled component
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