Next.js Discord

Discord Forum

Context API doesn't seem to work for me -Nextjs13

Unanswered
British Shorthair posted this in #help-forum
Open in Discord
British ShorthairOP
Hi I am tryin to get the Context API to work in my Next13 app, but I keep getting *undefined *as value returned from the context. Any function call (e.g. a fetch request ) that is called in a page/component gives the <function_name> is not a function error. I am trying not to go into the rabbit hole of redux as my app is small

3 Replies

Shy Albatross
cool story but unless you show the code, nobody will know the context
British ShorthairOP
'use client';
import { useContext, createContext, useState } from "react";

export const AuthContext = createContext()


function AuthProvider({children}){
    const [test,setTest] = useState('test material')
    
   const test2 = 'kiln'



    return (
        <AuthContext.Provider value={{test, test2}}>
            {children}
        </AuthContext.Provider>
    )
}

export default AuthProvider

@Shy Albatross the context
Shy Albatross
where did you put this context provider and how are you attempting to read it in components?