UNPKG

lynx-form-x

Version:

LynxFormX is a lightweight and intuitive form library built for the Lynx framework for mobile development. It streamlines form management by automatically binding fields, handling validation, and providing easy-to-use hooks for custom field manipulation—a

20 lines (19 loc) • 637 B
import { useContext } from '@lynx-js/react'; import { useEffect } from 'react'; import { formContext } from './Form.jsx'; export const Field = ({ children, name, bindinput, bindblur, ...props }) => { const { handleBlur, handleInput, values, setValue } = useContext(formContext); useEffect(() => { if (!values[name]) setValue(name, ''); }, []); return (<input //@ts-ignore bindinput={(event) => { handleInput(name)(event); bindinput?.(event); }} bindblur={(event) => { handleBlur(name)(); bindblur?.(event); }} {...props}/>); };