Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Custom hook is not a function React

When I try and call a function from my custom hook I get back an error when the screen loads saying setAuth is not a function.

useAuth.js

import { useContext } from "react";
import AuthContext from "../context/AuthProvider";
const useAuth = () => {
  return useContext(AuthContext);
}
export default useAuth;

login.js

import useAuth from '../hooks/useAuth';
...
const Login = () => {
 const { setAuth } = useAuth();
 ....
 setAuth({ email, password, accessToken });
 ...
 }

If I try and display typeof(setAuth) I get undifined.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to ensure your AuthContext has a setAuth function. Where you are calling your AuthContext.Provider you must provide setAuth function in the value prop

<AuthContext.Provider value={{ setAuth }}>

You can then access setAuth

const useAuth = () => {
 const { setAuth } = useContext(AuthContext);
 return setAuth
}

login.js

const Login = () => {
 const setAuth = useAuth();
 ....
 setAuth({ email, password, accessToken });
 ...
 }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!