A
A
Alexander2021-03-13 12:49:58
React
Alexander, 2021-03-13 12:49:58

What to replace stopSubmit from Redux Form in Formik?

Please tell me what can be replaced in Formik? Are there any analogues? I need to rewrite this code in Formik, thanks in advancestopSubmit(form:String, errors:Object)


import {stopSubmit } from 'redux-form'
   dispatch(stopSubmit('login', { _error: message }))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
georgeBushJn, 2022-01-03
@georgeBushJn

You probably don't need any more. But maybe someone can help.
There is setStatus, you can read about it, I'll just explain a little. It works a little differently, because formik doesn't create form in redux. In the onSubmit method in formik, add setStatus to the desired function. Like this:

onSubmit: (values, submitProps) => {
            let formData = {
                email: values.email,
                password: values.password,
                rememberMe: values.checkbox,
            }
            props.onSubmit(formData, submitProps.setStatus)
            submitProps.resetForm()
        }

I use thunk for api and call setStatus there to pass error
export const login = (loginData, setStatus) => {
    return (dispatch) => {
        authAPI.login(loginData)
            .then(data => {
                if(data.data.resultCode === 0) {
                    dispatch(authMe(true))
                } else {
                    setStatus({error: data.data.messages})
                }
            })
    }
}

And then you can apply in the form itself for the status.
formik.status.error

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question