Skip to content
Permalink
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

useValueHistory

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 (
     <DisplayDemo>
       <p>Count: {count}</p>
       <p>The history of the `count` state is:</p>
       <blockquote>
          { countHistory.join(', ') }
       </blockquote>
     </DisplayDemo>
   );
};

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