Skip to content

Instantly share code, notes, and snippets.

@monners
Created June 25, 2020 00:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save monners/7f7dc79e2d3dd4e36e236ec94206879e to your computer and use it in GitHub Desktop.
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.
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