mirror of
https://github.com/getwax/bls-wallet.git
synced 2026-04-23 03:00:37 -04:00
26 lines
561 B
TypeScript
26 lines
561 B
TypeScript
import { useEffect, useState } from 'react';
|
|
import AsyncReturnType from '../types/AsyncReturnType';
|
|
import forEach from './forEach';
|
|
|
|
import { IReadableCell } from './ICell';
|
|
|
|
export default function useCell<C extends IReadableCell<unknown>>(
|
|
cellParam: C,
|
|
) {
|
|
type T = AsyncReturnType<C['read']>;
|
|
const cell = cellParam as IReadableCell<T>;
|
|
|
|
const [value, setValue] = useState<T>();
|
|
|
|
useEffect(() => {
|
|
const { stop } = forEach(cell, setValue);
|
|
|
|
return () => {
|
|
setValue(undefined);
|
|
stop();
|
|
};
|
|
}, [cell]);
|
|
|
|
return value;
|
|
}
|