ViraStack
  • Akademi
  • Hakkında
  • Destek
Genel BakışBaşlangıçÖrnekler

Başlangıç

  • Giriş
  • 1.0'dan geçiş
  • llms.txt
  • llms-full.txt

Kullanım

  • useViraPassword()
  • Güç
  • Parola tekrarı
  • React Hook Form
  • Erişilebilirlik
  • Özelleştirme

Sunucu

  • Sunucu doğrulaması
  • Sızmış parolalar

Başvuru

  • Yardımcılar
  • Tipler
  • UI kütüphaneleri
  • Karşılaştırma

Parola tekrarı

Aynı hook ve matchWith ile parola tekrarı alanı.

Temel kullanım

Ayrı bir hook yoktur. Tekrar alanına matchWith verin: matches true, false veya alan boşken null olur. İki değer sunucudaki gibi NFKC sonrası karşılaştırılır.

Repeat the password.

// components/new-password-fields.tsx
"use client";
 
import { useState } from "react";
 
import { useViraPassword } from "@virastack/password";
 
export function NewPasswordFields() {
  const [password, setPassword] = useState("");
 
  const { inputProps, btnProps } = useViraPassword({
    inputProps: { value: password, onChange: (event) => setPassword(event.target.value) },
  });
  // Same hook with matchWith. Each field keeps its own show/hide button.
  const {
    inputProps: confirmProps,
    btnProps: confirmButton,
    matches,
  } = useViraPassword({ matchWith: password });
 
  return (
    <>
      <label htmlFor={inputProps.id}>New password</label>
      <div>
        <input {...inputProps} />
        <button {...btnProps} />
      </div>
 
      <label htmlFor={confirmProps.id}>Confirm password</label>
      <div>
        <input {...confirmProps} />
        <button {...confirmButton} />
      </div>
 
      <p aria-live="polite">
        {matches === null && "Repeat the password."}
        {matches === true && "Passwords match."}
        {matches === false && "Passwords don't match."}
      </p>
    </>
  );
}

rule

rule.validate her zaman en son matchWith'i okur; aynı nesne register()'a verilebilir. Parola değişince tekrar alanını yeniden kontrol etmek için deps'e bakın.

const password = useWatch({ control: form.control, name: "password" })
const { inputProps, rule } = useViraPassword({ matchWith: password })
 
<input {...inputProps} {...form.register("confirm", rule)} />
// değerler farklıysa "password.mismatch" (boş tekrar alanı da geçmez)

Ortak görünürlük

Her alanın kendi toggle'ı vardır. İkisini birlikte göstermek için tek state ile kontrol edin:

const [visible, setVisible] = useState(false)
 
const shared = { visible, onVisibleChange: setVisible }
 
const passwordField = useViraPassword(shared)
const confirmField = useViraPassword({ ...shared, matchWith: password })
ÖncekiGüçSonrakiReact Hook Form

Bu sayfada

  • Temel kullanım
  • rule
  • Ortak görünürlük
Hata mı var? Düzeltin