Skip to content

Commit eca62a1

Browse files
committed
fix AuthContext and sepaprate context
1 parent 7f8ad56 commit eca62a1

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

client/src/context/AuthContext.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React, { createContext, useState, useEffect } from 'react';
1+
import React, { useState, useEffect } from 'react';
22
import { getProfile } from '../api/auth';
3+
import { AuthContext } from './useAuth';
34

4-
export const AuthContext = createContext();
55

66
export const AuthProvider = ({ children }) => {
77
const [user, setUser] = useState(null);

client/src/context/useAuth.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useContext } from 'react';
2-
import { AuthContext } from './AuthContext';
1+
import { useContext, createContext } from 'react';
2+
3+
// The context instance lives here (a plain .js file) so AuthContext.jsx can
4+
// export only the AuthProvider component, satisfying react-refresh/only-export-components.
5+
export const AuthContext = createContext();
36

4-
// Separated from AuthContext.jsx so that file only exports a component
5-
// (AuthProvider), satisfying the react-refresh/only-export-components rule.
67
export const useAuth = () => {
78
const context = useContext(AuthContext);
89
if (!context) {

0 commit comments

Comments
 (0)