mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-30 16:01:17 -07:00
Chore: full react hooks eslint compliance (#7040)
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
export default function useDataPoints(pointsLimit, initialPoint) {
|
||||
const [dataPoints, setDataPoints] = useState(() => new Array(pointsLimit).fill(initialPoint));
|
||||
|
||||
const addDataPoint = useCallback(
|
||||
(dataPoint) => {
|
||||
setDataPoints((currentDataPoints) => {
|
||||
if (pointsLimit <= 0) return [];
|
||||
return [...currentDataPoints, dataPoint].slice(-pointsLimit);
|
||||
});
|
||||
},
|
||||
[pointsLimit],
|
||||
);
|
||||
|
||||
return [dataPoints, addDataPoint];
|
||||
}
|
||||
Reference in New Issue
Block a user