fumadocs-core
Version:
The React.js library for building a documentation website
17 lines (16 loc) • 511 B
JavaScript
import { t as isEqualShallow } from "../is-equal-BuZW92e4.js";
import { useState } from "react";
// src/utils/use-on-change.ts
/**
* @param value - state to watch
* @param onChange - when the state changed
* @param isUpdated - a function that determines if the state is updated
*/
function useOnChange(value, onChange, isUpdated = (a, b) => !isEqualShallow(a, b)) {
const [prev, setPrev] = useState(value);
if (isUpdated(prev, value)) {
onChange(value, prev);
setPrev(value);
}
}
export { useOnChange };