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
39 lines (38 loc) • 1.35 kB
JSX
export var ActionType;
(function (ActionType) {
ActionType[ActionType["SET_VALUE"] = 0] = "SET_VALUE";
ActionType[ActionType["SET_ERROR"] = 1] = "SET_ERROR";
ActionType[ActionType["SET_TOUCHED"] = 2] = "SET_TOUCHED";
ActionType[ActionType["SET_IS_SUBMITTING"] = 3] = "SET_IS_SUBMITTING";
ActionType[ActionType["RESET"] = 4] = "RESET";
})(ActionType || (ActionType = {}));
export function formReducer(state, action) {
switch (action.type) {
case ActionType.SET_VALUE:
return {
...state,
values: { ...state.values, [action.field]: action.value },
};
case ActionType.SET_ERROR:
return {
...state,
errors: { ...state.errors, [action.field]: action.error },
};
case ActionType.SET_TOUCHED:
return {
...state,
touched: { ...state.touched, [action.field]: action.touched },
};
case ActionType.SET_IS_SUBMITTING:
return { ...state, isSubmitting: action.isSubmitting };
case ActionType.RESET:
return {
values: action.initialValues,
errors: {},
touched: {},
isSubmitting: false,
};
default:
return state;
}
}