Skip to content
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

33 lines (24 sloc) 746 Bytes


Accepts a variable (possibly a prop or a state) and returns its history (changes through updates).

Why? πŸ’‘

  • You want to keep track of the history of a value

Basic Usage:

import { useState } from 'react'; 
import { useInterval, useValueHistory } from 'beautiful-react-hooks'; 

const TestComponent = () => {
   const [count, setCount] = useState(0);
   const countHistory = useValueHistory(count);
   useInterval(() => setCount(1 + count), 500);
   return (
       <p>Count: {count}</p>
       <p>The history of the `count` state is:</p>
          { countHistory.join(', ') }

<TestComponent />
You can’t perform that action at this time.