Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Isa1Maria opened this issue Jan 15, 2021 · 7 comments

Comments

@Isa1Maria
Copy link

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!

@KushalBiyani
Copy link

KushalBiyani commented Jan 17, 2021

may be using authprovider in the app.js file will work and wrapping the component inside it

import { AuthProvider } from "./context/AuthContext"

@valentinmagot
Copy link

I have the same issue and I also used authprovider in app.js. Does anyone have a solution for this issue ?

Thanks

@THEORIGINITE
Copy link

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!

@THEORIGINITE
Copy link

please if anyone has got the solution please tell me

@Ayan-Ali
Copy link

Ayan-Ali commented Feb 15, 2021 via email

@apshada
Copy link

apshada commented May 7, 2021

In index.js File
wrap up your app Component with Auth Provider

import React from "react";
import ReactDOM from "react-dom";
import App from "./components/App";
import "bootstrap/dist/css/bootstrap.min.css";
import { AuthProvider } from "./contexts/AuthContext";

ReactDOM.render(
  <AuthProvider>
    <App />
  </AuthProvider>,
  document.getElementById("root")
);

https://ankurraina.medium.com/reactjs-pass-functions-through-context-typeerror-cannot-destructure-property-of-450a8edd55b6

@ghost
Copy link

ghost commented May 12, 2021

What happens if you switch it back to signup? is signup a function in the AuthContext? Also check what apshada said. I had a similar error and looking at these 3 things helped me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants