Use useEffectEvent for effects with deliberately narrow deps (#11550)
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {useEffect, useMemo, useRef, useState} from 'react'
|
||||
import {useEffect, useEffectEvent, useMemo, useRef, useState} from 'react'
|
||||
import {Platform, Text as RNText, View} from 'react-native'
|
||||
import {parseLanguageString} from '@atproto/syntax'
|
||||
import {
|
||||
@@ -332,15 +332,18 @@ function GuessedLanguage({
|
||||
onDeclineOuter()
|
||||
}
|
||||
|
||||
const metaRef = useNonReactiveObject(metadata)
|
||||
useEffect(() => {
|
||||
const logSuggestion = useEffectEvent(() => {
|
||||
ax.metric('composer:language:suggestLanguage', {
|
||||
os: Platform.OS,
|
||||
suggestedLanguage: language,
|
||||
currentTargetLanguages: metaRef.current.currentTargetLanguages,
|
||||
currentTargetLanguages: metadata.currentTargetLanguages,
|
||||
textLength: sanitizeTextForDetection(metadata.rawText).length,
|
||||
})
|
||||
}, [ax, language])
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
logSuggestion()
|
||||
}, [language])
|
||||
|
||||
return (
|
||||
<LanguageSuggestionButton
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useCallback, useEffect, useRef} from 'react'
|
||||
import {useCallback, useEffect, useEffectEvent, useRef} from 'react'
|
||||
import {StyleSheet, View} from 'react-native'
|
||||
import {Trans, useLingui} from '@lingui/react/macro'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
@@ -23,6 +23,11 @@ export function CustomFeedEmptyState() {
|
||||
const {currentAccount} = useSession()
|
||||
const hasLoggedDiscoverEmptyErrorRef = useRef(false)
|
||||
|
||||
const logDiscoverEmptyError = useEffectEvent((did: string) => {
|
||||
hasLoggedDiscoverEmptyErrorRef.current = true
|
||||
ax.metric('feed:discover:emptyError', {userDid: did})
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
// Log the empty feed error event
|
||||
if (feedFeedback.feedSourceInfo && currentAccount?.did) {
|
||||
@@ -31,10 +36,7 @@ export function CustomFeedEmptyState() {
|
||||
uri === DISCOVER_FEED_URI &&
|
||||
!hasLoggedDiscoverEmptyErrorRef.current
|
||||
) {
|
||||
hasLoggedDiscoverEmptyErrorRef.current = true
|
||||
ax.metric('feed:discover:emptyError', {
|
||||
userDid: currentAccount.did,
|
||||
})
|
||||
logDiscoverEmptyError(currentAccount.did)
|
||||
}
|
||||
}
|
||||
}, [feedFeedback.feedSourceInfo, currentAccount?.did])
|
||||
|
||||
Reference in New Issue
Block a user