Skip to content

Commit

Permalink
feat(form): helper methods for react hook form
Browse files Browse the repository at this point in the history
  • Loading branch information
yawetse committed Mar 24, 2021
1 parent 6f11d74 commit 021aca8
Show file tree
Hide file tree
Showing 35 changed files with 4,825 additions and 87 deletions.
10 changes: 7 additions & 3 deletions build/components.js
@@ -1,6 +1,6 @@
import React, { useState, useEffect, useContext, useReducer, useCallback, useMemo, useRef, useImperativeHandle, useLayoutEffect, useDebugValue, Fragment, Suspense, lazy, createContext } from "react";
import * as memoryCache from "memory-cache";
import { useForm, Controller, } from 'react-hook-form';
import { useForm, useController, useFieldArray, useWatch, Controller, } from 'react-hook-form';
import { ErrorMessage } from '@hookform/error-message';
// import {cache} from 'memory-cache';
// import cache from 'memory-cache';
Expand Down Expand Up @@ -488,12 +488,16 @@ export function getReactFunctionComponent(reactComponent = {}, functionBody = ""
getReactElementFromJSONX,
reactComponent,
resources,
props
props,
useForm,
useController,
useFieldArray,
useWatch,
];
//@ts-ignore
if (typeof functionBody === "function")
functionBody = functionBody.toString();
const functionComponent = Function("React", "useState", "useEffect", "useContext", "useReducer", "useCallback", "useMemo", "useRef", "useImperativeHandle", "useLayoutEffect", "useDebugValue", "getReactElementFromJSONX", "reactComponent", "resources", "props", `
const functionComponent = Function("React", "useState", "useEffect", "useContext", "useReducer", "useCallback", "useMemo", "useRef", "useImperativeHandle", "useLayoutEffect", "useDebugValue", "getReactElementFromJSONX", "reactComponent", "resources", "props", "useForm", "useController", "useFieldArray", "useWatch", `
'use strict';
const self = this || {};
Expand Down
6 changes: 6 additions & 0 deletions build/props.js
Expand Up @@ -610,6 +610,12 @@ export function getComputedProps(options = {}) {
: {}
: {})
: undefined;
if (jsonx.useformregister) {
jsonx.thiscontext = {
ref: ['reactHookForm', 'register'],
...jsonx.thiscontext,
};
}
const windowTraverse = typeof window !== "undefined" ? window : {};
const asyncprops = jsonx.asyncprops
? getJSONXProps({
Expand Down
2 changes: 2 additions & 0 deletions build/types/jsonx/jsonx.d.ts
Expand Up @@ -121,6 +121,8 @@ export interface jsonxElementProperties {
comparisonprops?: jsonxComparison[];
/** Display Prop: flag used to conditionally show elements when any comparison values are true */
comparisonorprops?: Boolean;
/** Applied Prop: modify jsonx properties */
useformregister?: boolean;
[index: string]: any;
}
export interface jsonx extends jsonxElementProperties, jsonxChildren {
Expand Down
1 change: 1 addition & 0 deletions build/types/jsonx/main.d.ts
Expand Up @@ -17,6 +17,7 @@ export interface Context {
disableRenderIndexKey?: boolean;
exposeEval?: boolean;
name?: string;
reactHookForm?: any;
}
export interface JSONContext extends Context {
returnJSON: true;
Expand Down
1 change: 1 addition & 0 deletions build/utils.js
Expand Up @@ -269,6 +269,7 @@ export function validateJSONX(jsonx = {}, returnAllErrors = false) {
"comparisonorprops",
"passprops",
"exposeprops",
"useformregister",
"debug",
"___stringifyChildren",
"___toStringChildren",
Expand Down

0 comments on commit 021aca8

Please sign in to comment.