mirror of
https://github.com/element-hq/element-web.git
synced 2025-12-05 01:10:40 +00:00
* Switch to React18 useId Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Enable react-compiler eslint Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix an easy one Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Disable in tests Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix usage of useRef as memoization Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix mutation of external values in hooks Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Make React compiler happy about some frankly non-issues Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Fix MapMock Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Iterate Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Revert MemberListViewModel.tsx changes and disable linter per line Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> * Make viewmodel compatible with react-compiler linter - Remove searchQuery ref/state and instead pass this query to the loadMember function. - Now we no longer need a separate search function --------- Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> Co-authored-by: R Midhun Suresh <hi@midhun.dev>
28 lines
867 B
TypeScript
28 lines
867 B
TypeScript
/*
|
|
Copyright 2024 New Vector Ltd.
|
|
Copyright 2024 The Matrix.org Foundation C.I.C.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
// Based on https://stackoverflow.com/a/61680184
|
|
|
|
import { DependencyList, useEffect, useRef } from "react";
|
|
|
|
export const useTransition = <D extends DependencyList>(callback: (...params: D) => void, deps: D): void => {
|
|
const func = useRef<(...params: D) => void>(callback);
|
|
|
|
useEffect(() => {
|
|
func.current = callback;
|
|
}, [callback]);
|
|
|
|
const args = useRef<D | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (args.current !== null) func.current(...args.current);
|
|
args.current = deps;
|
|
// eslint-disable-next-line react-compiler/react-compiler,react-hooks/exhaustive-deps
|
|
}, deps);
|
|
};
|