forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kookmin-sw#6 from capstone-maru/chore/recoil-templ…
…ate-code Chore/recoil template code
- Loading branch information
Showing
7 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useCallback, useMemo } from 'react'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { authState } from './auth.atom'; | ||
|
||
export const useAuthActions = () => { | ||
const [, setAuth] = useRecoilState(authState); | ||
|
||
const login = useCallback(() => { | ||
setAuth(prev => ({ ...prev, isLogin: true })); | ||
}, [setAuth]); | ||
const logout = useCallback(() => { | ||
setAuth(prev => ({ ...prev, isLogin: false })); | ||
}, [setAuth]); | ||
|
||
useMemo( | ||
() => ({ | ||
login, | ||
logout, | ||
}), | ||
[login, logout], | ||
); | ||
}; |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { atom } from 'recoil'; | ||
|
||
import { type AuthState } from './auth.model'; | ||
|
||
export const authState = atom<AuthState>({ | ||
key: 'authState', | ||
default: { | ||
isLogin: false, | ||
token: undefined, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
|
||
import { authState } from './auth.atom'; | ||
import { getIsLogin } from './auth.selector'; | ||
|
||
export const useAuthState = () => useRecoilState(authState); | ||
export const useAuthIsLogin = () => useRecoilValue(getIsLogin); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export interface AuthState { | ||
isLogin: boolean; | ||
token?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { selector } from 'recoil'; | ||
|
||
import { authState } from './auth.atom'; | ||
|
||
export const getIsLogin = selector<boolean>({ | ||
key: 'authState/isLogin', | ||
get: ({ get }) => { | ||
const auth = get(authState); | ||
return auth.isLogin; | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
|
||
export * from './auth.action'; | ||
export * from './auth.atom'; | ||
export * from './auth.hook'; | ||
export * from './auth.model'; | ||
export * from './auth.selector'; |