score:1

Accepted answer
import React from "react";
import { SubmissionError } from "redux-form";
import ax from "axios";

async function submit(values) {
  const result = await ax.get("./UserCredentials.json").then(res => {
    console.log(values);
    if (!values.username || !values.password) {
      throw new SubmissionError({
        username: "Please enter your credentials",
        _error: "Login failed!"
      });
    } else if (res.data[0].username !== values.username) {
      throw new SubmissionError({
        username: "User does not exist",
        _error: "Login failed!"
      });
    } else if (res.data[0].password !== values.password) {
      throw new SubmissionError({
        password: "Wrong password",
        _error: "Login failed!"
      });
    }
  });

  if (result) {
    // do your stuff
  }
}

export default submit;

Related Query

More Query from same tag