react-formal
Version:
Classy HTML form management for React
22 lines (19 loc) • 559 B
JavaScript
import { useBindingContext } from './BindingContext';
/**
* Returns the current Field value at the provided path.
*
* @param {string} field a field path to observe.
* @returns {any}
*/
/**
* Returns an array of values for the provided field paths.
*
* @param {string[]} fields a set of field paths to observe.
* @returns {Array<any>}
*/
function useFormValues(fields) {
const ctx = useBindingContext();
if (!ctx) return;
return Array.isArray(fields) ? fields.map(f => ctx.getValue(f)) : ctx.getValue(fields);
}
export default useFormValues;