-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42497 from Expensify/neil-public-room-composer
Show composer on public rooms after signing in
- Loading branch information
Showing
3 changed files
with
38 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import isEqual from 'lodash/isEqual'; | ||
import {useRef} from 'react'; | ||
|
||
/** | ||
* This hook returns a reference to the provided value, | ||
* but only updates that reference if a deep comparison indicates that the value has changed. | ||
* | ||
* This is useful when working with objects or arrays as dependencies to other hooks like `useEffect` or `useMemo`, | ||
* where you want the hook to trigger not just on reference changes, but also when the contents of the object or array change. | ||
* | ||
* @example | ||
* const myArray = // some array | ||
* const deepComparedArray = useDeepCompareRef(myArray); | ||
* useEffect(() => { | ||
* // This will run not just when myArray is a new array, but also when its contents change. | ||
* }, [deepComparedArray]); | ||
*/ | ||
export default function useDeepCompareRef<T>(value: T): T | undefined { | ||
const ref = useRef<T>(); | ||
if (!isEqual(value, ref.current)) { | ||
ref.current = value; | ||
} | ||
return ref.current; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters