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,11 @@
|
||||
import {useCallback, useEffect, useId, useRef, useState} from 'react'
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useEffectEvent,
|
||||
useId,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {useLingui} from '@lingui/react/macro'
|
||||
import type * as HlsTypes from 'hls.js'
|
||||
@@ -274,6 +281,14 @@ function useHLS({
|
||||
},
|
||||
)
|
||||
|
||||
/*
|
||||
* The hls handler below must call the latest `updateCuePositions` without the
|
||||
* effect tearing down and re-attaching every time its identity changes.
|
||||
*/
|
||||
const onSubtitleFragProcessed = useEffectEvent(() => {
|
||||
updateCuePositions()
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (!videoRef.current) return
|
||||
if (!Hls) return
|
||||
@@ -312,7 +327,7 @@ function useHLS({
|
||||
})
|
||||
|
||||
hls.on(Hls.Events.SUBTITLE_FRAG_PROCESSED, () => {
|
||||
updateCuePositions()
|
||||
onSubtitleFragProcessed()
|
||||
})
|
||||
|
||||
hls.on(Hls.Events.FRAG_BUFFERED, (_event, {frag}) => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {useEffect, useMemo, useRef, useState} from 'react'
|
||||
import {useEffect, useEffectEvent, useMemo, useRef, useState} from 'react'
|
||||
import {
|
||||
TextInput,
|
||||
type TextInputContentSizeChangeEvent,
|
||||
@@ -141,13 +141,17 @@ export function AutosizedTextarea({
|
||||
* Reset native height state after a programmatic clear. Android uses it as
|
||||
* the explicit input height, while iOS uses it to decide when to scroll.
|
||||
*/
|
||||
const reportHeight = useEffectEvent((height: number) => {
|
||||
onUpdateHeight?.(height)
|
||||
})
|
||||
|
||||
const prevRawValue = useRef(rawValue || '')
|
||||
useEffect(() => {
|
||||
if (!IS_NATIVE) return
|
||||
if (rawValue === undefined) return // uncontrolled
|
||||
if (prevRawValue.current?.length && rawValue === '') {
|
||||
setNativeHeight(minInputHeight)
|
||||
onUpdateHeight?.(minInputHeight)
|
||||
reportHeight(minInputHeight)
|
||||
}
|
||||
prevRawValue.current = rawValue
|
||||
}, [rawValue, minInputHeight])
|
||||
|
||||
Reference in New Issue
Block a user