Utilities & Refs
useFreshTick
About
Like useFreshRef but specifically for functions
Examples
import { useFreshTick } from "rooks";
import { useEffect, useState } from "react";
/* eslint-disable */
export default function App() {
const [currentValue, setCurrentValue] = useState(0);
function Increment() {
setCurrentValue(currentValue + 1);
}
const freshTick = useFreshTick(Increment);
useEffect(() => {
const intervalId = setInterval(() => {
freshTick();
}, 1000);
return () => clearInterval(intervalId);
}, []);
return (
<div className="App">
<h1> Rooks : useFreshTick example</h1>
<h3>
current value : <i>{currentValue} </i>
</h3>
</div>
);
}Arguments
| Argument value | Type | Description |
|---|---|---|
| callback | function | The function call which needs to be fresh at all times |
Returns
| Return value | Type | Description | Default value |
|---|---|---|---|
| ref | function | A function with fresh args | undefined |