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 'username' of '(0 , react__WEBPACK_IMPORTED_MODULE_0__.useContext)(...)' as it is undefined. #5

Open
ZhechengLiao opened this issue Dec 4, 2021 · 2 comments

Comments

@ZhechengLiao
Copy link

ZhechengLiao commented Dec 4, 2021

I think it might not import the username, but I check a lot of time, I did't find anything different with ur code, pls help me!!!

// pages\index.js
import React, { useContext } from "react";

import { Context } from "../context";

import { useRouter } from "next/router";

import axios from "axios";

export default function Auth() {

const { username, setUsername, secret, setSecret } = useContext(Context);
// context\index.js
import React, { useState, createContext} from "react";

export const Context = createContext();

export const ContextProvider = (props) => {
    const [username, setUsername] = useState("");
    const [secret, setSecret] = useState("");

    const value = {
        username,
        setUsername,
        secret,
        setSecret,
    };

    return <Context.Provider value={value}>{props.children}</Context.Provider>;
};
@lry41
Copy link

lry41 commented May 19, 2022

hello, have you fix this ?

@roshan-ican
Copy link

I am stuck at the similar problem

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

3 participants