Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryanhefner/react-speedo

⏱ Tooling to help you monitor the performance of your React applications.
https://github.com/ryanhefner/react-speedo

performance react react-hooks

Last synced: about 1 month ago
JSON representation

⏱ Tooling to help you monitor the performance of your React applications.

Awesome Lists containing this project

README

        

# react-speedo

Tooling to help you monitor the performance of your React applications.

## Install

Via [npm](https://npmjs.com/package/react-speedo)

```sh
npm install react-speedo
```

Via [Yarn](https://yarn.pm/react-speedo)

```sh
yarn add react-speedo
```

## How to use

### `useSpeedo` (Hook)

```js
import { useRef, useState } from 'react'
import { useSpeedo } from 'react-speedo'

const YourComponent = () => {
const { begin, end, value } = useSpeedo()
const [run, setRun] = useState(true)
const animationFrameRef = useRef(null)

useEffect(() => {
const tick = async () => {
begin()

...[some async tasks or other heavy code]

end()
}

if (run && !animationFrameRef.current) {
animationFrameRef.current = requestAnimationFrame(tick)
} else if (!run && animationFrameRef.current) {
cancelAnimationFrame(animationFrameRef.current)
animationFrameRef.current = null
}
}, [run])

return

{`${value}fps`}


}

```

## License

[MIT](LICENSE) © [Ryan Hefner](https://www.ryanhefner.com)