Created
June 25, 2020 00:36
-
-
Save monners/7f7dc79e2d3dd4e36e236ec94206879e to your computer and use it in GitHub Desktop.
Component that counts and displays the number of times it has been rendered.
This file contains hidden or 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 from 'react' | |
import styled from 'styled-components' | |
export default function RenderCount() { | |
const renders = React.useRef(0) | |
return <Circle>{++renders.current}</Circle> | |
} | |
const size = 30 | |
const Circle = styled.i` | |
position: absolute; | |
top: 0; | |
right: 0; | |
font-style: normal; | |
text-align: center; | |
height: ${size}px; | |
width: ${size}px; | |
line-height: ${size}px; | |
border-radius: ${size / 2}px; | |
border: 1px solid #ddd; | |
background: #eee; | |
` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment