Replace lande with native language detection (#9974)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: DS Boyce <260543580+ds-boyce@users.noreply.github.com> Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
@@ -1,17 +1,25 @@
|
||||
import {useCallback, useInsertionEffect, useRef} from 'react'
|
||||
|
||||
// This should be used sparingly. It erases reactivity, i.e. when the inputs
|
||||
// change, the function itself will remain the same. This means that if you
|
||||
// use this at a higher level of your tree, and then some state you read in it
|
||||
// changes, there is no mechanism for anything below in the tree to "react"
|
||||
// to this change (e.g. by knowing to call your function again).
|
||||
//
|
||||
// Also, you should avoid calling the returned function during rendering
|
||||
// since the values captured by it are going to lag behind.
|
||||
export function useNonReactiveCallback<T extends Function>(fn: T): T {
|
||||
const ref = useRef(fn)
|
||||
const noop = () => {}
|
||||
|
||||
/**
|
||||
* This should be used sparingly. It erases reactivity, i.e. when the inputs
|
||||
* change, the function itself will remain the same. This means that if you use
|
||||
* this at a higher level of your tree, and then some state you read in it
|
||||
* changes, there is no mechanism for anything below in the tree to "react" to
|
||||
* this change (e.g. by knowing to call your function again).
|
||||
*
|
||||
* Also, you should avoid calling the returned function during rendering since
|
||||
* the values captured by it are going to lag behind.
|
||||
*
|
||||
* For objects, see `useNonReactiveObject` instead.
|
||||
*/
|
||||
export function useNonReactiveCallback<T extends Function = () => void>(
|
||||
fn?: T,
|
||||
): T {
|
||||
const ref = useRef<T>((fn ?? noop) as T)
|
||||
useInsertionEffect(() => {
|
||||
ref.current = fn
|
||||
ref.current = (fn ?? noop) as T
|
||||
}, [fn])
|
||||
return useCallback(
|
||||
(...args: any) => {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import {useInsertionEffect, useRef} from 'react'
|
||||
|
||||
/**
|
||||
* This should be used sparingly. It erases reactivity, i.e. when the inputs
|
||||
* change, the returned object itself will remain the same. This means that if
|
||||
* you use this at a higher level of your tree, and then some state you read in
|
||||
* it changes, there is no mechanism for anything below in the tree to "react"
|
||||
* to this change (e.g. by knowing to call your function again).
|
||||
*
|
||||
* For callbacks, see `useNonReactiveCallback` instead.
|
||||
*/
|
||||
export function useNonReactiveObject<T extends Record<string, unknown>>(
|
||||
o: T,
|
||||
): React.RefObject<T> {
|
||||
const ref = useRef(o)
|
||||
useInsertionEffect(() => {
|
||||
ref.current = o
|
||||
}, [o])
|
||||
return ref
|
||||
}
|
||||
Reference in New Issue
Block a user