Develop ultra fast with Prismane 🎉

required

This validator checks if a given variable has a value or not.

Basic Usage

import { required } from "@prismane/core/validators";

console.log(required("Ivan is very cool")); // Will return null
console.log(required(""));
// Will return `This field is required!`

useForm Hook Usage

function Demo() {
  const { handleSubmit, handleReset, register } = useForm({
    fields: {
      username: {
        value: "",
        validators: {
          required: (v: string) => required(v),
        },
      },
    },
  });

  return (
    <Form
      onSubmit={(e: any) => {
        handleSubmit(e, (v: any) => console.log(v));
      }}
      onReset={() => handleReset()}
      maw={300}
    >
      <TextField
        placeholder="Enter username: "
        label="Username:"
        {...register("username")}
      />
      <Button type="submit">Submit</Button>
    </Form>
  );
}

API

Parameters

NameTypeDescription
valuestring / booleanThe value that will be validated.