theshadowboxers
theshadowboxers
SSolidJS
Created by theshadowboxers on 8/8/2023 in #support
Resource with createContext?
Thank you, this was helpful! Your final comment about the provider not existing yet made the light bulb come on and I realised I was calling useContext in the App component which was also where I had the AuthProvider tag... so it didn't exist when I was calling useContext. Moved AuthProvider to the index.tsx and now the useContext works in App component. Appreciate your help!
4 replies
SSolidJS
Created by theshadowboxers on 8/8/2023 in #support
Resource with createContext?
const AuthContext = createContext(()=>{});

export function AuthProvider(props: { children: any }) {
const [authState, setAuthState] = createSignal<AuthState>();
const [user] = createResource(authState, getUser);
const memoizedUser = createMemo(() => {
let u = user();
console.log("MEMO", u);
return u;
});

initOkta();
okta.authStateManager.subscribe(authState => {
setAuthState(authState);
});

return (
<AuthContext.Provider value={memoizedUser}>
{props.children}
</AuthContext.Provider>
);
}
const AuthContext = createContext(()=>{});

export function AuthProvider(props: { children: any }) {
const [authState, setAuthState] = createSignal<AuthState>();
const [user] = createResource(authState, getUser);
const memoizedUser = createMemo(() => {
let u = user();
console.log("MEMO", u);
return u;
});

initOkta();
okta.authStateManager.subscribe(authState => {
setAuthState(authState);
});

return (
<AuthContext.Provider value={memoizedUser}>
{props.children}
</AuthContext.Provider>
);
}
4 replies