Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const transformStatus = (type: string, ref: any) => {
switch (type) {
case LifeCycleTypes.ON_FORM_INIT:
return 'initialize'
case LifeCycleTypes.ON_FORM_SUBMIT_START:
ref.current.submitting = true
return 'submitting'
case LifeCycleTypes.ON_FORM_SUBMIT_END:
ref.current.submitting = false
return 'submitted'
default:
return ref.current.submitting ? 'submitting' : type
}
}if (!env.effectStart || env.effectEnd) {
throw new Error(
'EffectHook must be called synchronously within the effects callback function.'
)
}
if (!env.effectSelector) {
throw new Error('Can not found effect hook selector.')
}
return env.effectSelector(type, ...args)
}
export const FormEffectHooks = {
onFormWillInit$: createEffectHook(
LifeCycleTypes.ON_FORM_WILL_INIT
),
onFormInit$: createEffectHook(LifeCycleTypes.ON_FORM_INIT),
onFormChange$: createEffectHook(LifeCycleTypes.ON_FORM_CHANGE),
onFormInputChange$: createEffectHook(
LifeCycleTypes.ON_FORM_INPUT_CHANGE
),
onFormInitialValueChange$: createEffectHook(
LifeCycleTypes.ON_FORM_INITIAL_VALUES_CHANGE
),
onFormReset$: createEffectHook(LifeCycleTypes.ON_FORM_RESET),
onFormSubmitValidateStart$: createEffectHook(
LifeCycleTypes.ON_FORM_SUBMIT_VALIDATE_START
),
onFormSubmitValidateSuccess$: createEffectHook(
LifeCycleTypes.ON_FORM_SUBMIT_VALIDATE_SUCCESS
),
onFormSubmitValidateFailed$: createEffectHook(export const FormSpy: React.FunctionComponent = props => {
const broadcast = useContext(BroadcastContext)
const form = useContext(FormContext)
const initializedRef = useRef(false)
const [type, setType] = useState(LifeCycleTypes.ON_FORM_INIT)
const [state, dispatch] = useReducer(
(state, action) => props.reducer(state, action, form),
{}
)
const subscriber = useCallback(({ type, payload }) => {
if (initializedRef.current) return
if (isStr(props.selector) && FormPath.parse(props.selector).match(type)) {
setType(type)
dispatch({
type,
payload
})
} else if (isArr(props.selector) && props.selector.indexOf(type) > -1) {
setType(type)
dispatch({
type,export const useFormSpy = (props: IFormSpyProps): ISpyHook => {
const broadcast = useContext(BroadcastContext)
const form = useContext(FormContext)
const initializedRef = useRef(false)
const subscriberId = useRef()
const [type, setType] = useState(LifeCycleTypes.ON_FORM_INIT)
const [state, dispatch] = useReducer(
(state, action) => props.reducer(state, action, form),
{}
)
const subscriber = useCallback(({ type, payload }) => {
if (initializedRef.current) return
setTimeout(() => {
if (isStr(props.selector) && FormPath.parse(props.selector).match(type)) {
setType(type)
dispatch({
type,
payload
})
} else if (isArr(props.selector) && props.selector.indexOf(type) > -1) {
setType(type)
dispatch({