Created
January 29, 2023 06:25
-
-
Save ms314006/910aebb095930982b5d1d1f501a880d3 to your computer and use it in GitHub Desktop.
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
import { useQuery } from 'react-query'; | |
import apis from '../apis'; | |
const useUser = () => useQuery( | |
['user'], | |
async () => { | |
const createGuestUser = () => ({ | |
name: '遊客', | |
submitComment: () => { /* 導到登入頁面 */ }, | |
}); | |
const { data: user } = await apis.getUser(); | |
return user || createGuestUser(); | |
} | |
); | |
export default useUser; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment