Simplify editable cell signature
Signed-off-by: Jonathan <contact@grafikart.fr>
This commit is contained in:
18
packages/hooks/src/useStateWithRef.ts
Normal file
18
packages/hooks/src/useStateWithRef.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { useCallback, useRef, useState } from "react";
|
||||
|
||||
/**
|
||||
* A useState hook that also returns a ref to the current state (usable in callbacks)
|
||||
*/
|
||||
export function useStateWithRef<T>(initialValue: T) {
|
||||
const [state, setState] = useState(initialValue);
|
||||
const ref = useRef(state);
|
||||
|
||||
return [
|
||||
state,
|
||||
useCallback((v: T) => {
|
||||
setState(v);
|
||||
ref.current = v;
|
||||
}, []),
|
||||
ref,
|
||||
] as const;
|
||||
}
|
||||
Reference in New Issue
Block a user