Skip to content

TypeError: Cannot destructure property 'register' of 'Object(...)(...)' as it is undefined. #7

@Isa1Maria

Description

@Isa1Maria

Captura de ecrã 2021-01-15, às 04 37 18

Hi Kyle! First of all, great tutorial!

I've done everything like you (your "signup" === my "register") and this error still occurs to me and I'm not capable of finding out what's wrong.
Would you please help me?

I've written like this:

``
import React, { useRef, useState } from "react";
import { Form, Button, Card, Alert } from "react-bootstrap";
import { useAuth } from "../contexts/AuthContext";
import { Link, useHistory } from "react-router-dom";

export default function Register() {
const nameRef = useRef()
const usernameRef = useRef()
const emailRef = useRef()
const passwordRef = useRef()
const confirmPasswordRef = useRef()
const { register } = useAuth()
const [error, setError] = useState("")
const [loading, setLoading] = useState(false)
const history = useHistory()

async function handleSubmit(e) {
e.preventDefault()

if (passwordRef.current.value !== confirmPasswordRef.current.value) {
  return setError("Passwords don't match!")
}

try {
  setError("")
  setLoading(false)
  setLoading(true)
  await register(emailRef.current.value, passwordRef.current.value)
history.push("/")
} catch {
  setError("Failed to create an account.")
}

}´´

Thank you for your attention!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions