Invalid value for prop `disabled` on <button> tag. Either remove it from the element, or pass a string or number value to keep it in the DOM

import React, { Component } from “react”;

import Input from “…/common/input”;

import Joi from “joi-browser”;

class LoginForm extends Component {

state = {

account: {

  username: "",

  password: "",

},

errors: {},

};

schema = {

username: Joi.string().required().label("Username"),

password: Joi.string().required().label("Password"),

};

abortEarly = {

abortEarly: false,

};

handleSubmit = (event) => {

event.preventDefault();

const errors = this.validate();

if (errors) return;

console.log("submitted");

};

validate = () => {

const result = Joi.validate(

  this.state.account,

  this.schema,

  this.abortEarly

);

const errors = {};

console.log(result);

if (!result.error) return null;

result.error.details.map((detail) => {

  errors[detail.path[0]] = detail.message;

  return detail.path[0];

});

this.setState({ errors });

return errors;

};

validateProperty = ({ name, value }) => {

const propertyTobeValidated = { [name]: value };

const schema = { [name]: this.schema[name] };

const { error } = Joi.validate(propertyTobeValidated, schema);

return error ? error.details[0].message : null;

};

handleChange = ({ currentTarget }) => {

const errors = { ...this.state.errors };

const error = this.validateProperty(currentTarget);

if (error) errors[currentTarget.name] = error;

else delete errors[currentTarget.name];

const account = { ...this.state.account };

account[currentTarget.name] = currentTarget.value;

this.setState({ account, errors });

};

render() {

const { account, errors } = this.state;

return (

  <div>

    <h1>Login</h1>

    <form onSubmit={this.handleSubmit}>

      <Input

        label="Username"

        name="username"

        value={account.username}

        onChange={this.handleChange}

        error={errors.username}

      ></Input>

      <Input

        label="Password"

        name="password"

        value={account.password}

        onChange={this.handleChange}

        error={errors.password}

      ></Input>

      <button disabled={this.validate} className="btn btn-primary">

        Login

      </button>

    </form>

  </div>

);

}

}

export default LoginForm;

I’m guessing that this.validate has to be a boolean value?

validate method is either returning null or errors object.

Your validate method is returning errors as an object.

The way to apply the disabled prop on the eventual rendered node is to pass it an argument that will evaluate to either true or false. The latter is kind of redundant as it will ignore the entire prop when the value is false anyway.

So, something along the lines of:
disabled = {Object.values(this.state.errors).length > 0 true : false? }