Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3492583
D6419.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D6419.diff
View Options
diff --git a/lib/hooks/ens-cache.js b/lib/hooks/ens-cache.js
--- a/lib/hooks/ens-cache.js
+++ b/lib/hooks/ens-cache.js
@@ -11,9 +11,6 @@
function useStringForUser(
user: ?(RelativeUserInfo | RelativeMemberInfo),
): ?string {
- const rawStringForUser = user ? stringForUser(user) : null;
- const [ensName, setENSName] = React.useState<?string>(null);
-
const ethAddress = React.useMemo(() => {
if (
!user ||
@@ -26,15 +23,22 @@
return user.username;
}, [user]);
+ const cacheContext = React.useContext(ENSCacheContext);
+ const { ensCache } = cacheContext;
+ const cachedResult =
+ ethAddress && ensCache
+ ? ensCache.getCachedNameForAddress(ethAddress)
+ : null;
+
+ const [ensName, setENSName] = React.useState<?string>(null);
+
React.useEffect(() => {
// Whenever the ETH address changes, clear out ENS name before requery below
setENSName(null);
}, [ethAddress]);
- const cacheContext = React.useContext(ENSCacheContext);
- const { ensCache } = cacheContext;
React.useEffect(() => {
- if (!ethAddress || !ensCache) {
+ if (cachedResult || !ethAddress || !ensCache) {
return;
}
let cancelled = false;
@@ -47,9 +51,17 @@
return () => {
cancelled = true;
};
- }, [ethAddress, ensCache]);
+ }, [cachedResult, ethAddress, ensCache]);
- return ensName ?? rawStringForUser;
+ if (ensName) {
+ return ensName;
+ } else if (cachedResult) {
+ return cachedResult;
+ } else if (user) {
+ return stringForUser(user);
+ } else {
+ return null;
+ }
}
export { useStringForUser };
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 12:41 AM (20 h, 51 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2679332
Default Alt Text
D6419.diff (1 KB)
Attached To
Mode
D6419: [lib] Show cached ENS names on first render
Attached
Detach File
Event Timeline
Log In to Comment