Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(base): refactor/clean up user-store
- Improves dataloader caching - Deprecates the `userStore.currentUser` observable of events in favor of the `userStore.me` Observable of `CurrentUser | null` - Improves typings and adds strict mode for better type safety - Adds a `useCurrentUser()` hook that returns the current user (or `null` if logged out)
- Loading branch information
Showing
6 changed files
with
125 additions
and
114 deletions.
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
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
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,7 +1,12 @@ | ||
import userStore from 'part:@sanity/base/user' | ||
|
||
import {LoadableState, useLoadable} from '../../util/useLoadable' | ||
import {User} from './types' | ||
import {CurrentUser, User} from './types' | ||
|
||
export function useUser(userId: string): LoadableState<User> { | ||
return useLoadable(userStore.observable.getUser(userId)) | ||
} | ||
|
||
export function useCurrentUser(): LoadableState<CurrentUser> { | ||
return useLoadable(userStore.me) | ||
} |
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,3 @@ | ||
{ | ||
"extends": "../../../tsconfig.strict", | ||
} |
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
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,5 +1,5 @@ | ||
export {useDocumentPresence, useGlobalPresence} from './datastores/presence/hooks' | ||
export {useUser} from './datastores/user/hooks' | ||
export {useUser, useCurrentUser} from './datastores/user/hooks' | ||
export {useUserColor} from './user-color/hooks' | ||
export {useTimeAgo} from './time/useTimeAgo' | ||
export {useDocumentValues} from './datastores/document/useDocumentValues' |