Skip to content

Instantly share code, notes, and snippets.

@ms314006
Created January 29, 2023 06:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms314006/910aebb095930982b5d1d1f501a880d3 to your computer and use it in GitHub Desktop.
Save ms314006/910aebb095930982b5d1d1f501a880d3 to your computer and use it in GitHub Desktop.
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