syncbasestore
Version:
Lightweight reactive store with built-in filtering and async state handling
16 lines (15 loc) • 469 B
JavaScript
import { useCallback } from 'react';
export function buildBase(store) {
const setField = useCallback((key, value, validator) => {
const validation = validator ? validator(value) : { status: 'idle' };
store.setState(prev => ({
...prev,
[key]: {
value,
status: validation.status,
message: validation.message
}
}));
}, [store]);
return { setField };
}