-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Emit component updated metrics during table interactions (#2901)
- Loading branch information
1 parent
fd86923
commit b1a1a4b
Showing
10 changed files
with
228 additions
and
161 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
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
62 changes: 0 additions & 62 deletions
62
src/internal/hooks/use-component-analytics/__tests__/use-component-analytics.test.tsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,21 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { useEffect, useRef } from 'react'; | ||
|
||
/* | ||
* This hook allows setting an DOM attribute after the first render, without rerendering the component. | ||
*/ | ||
export function useDOMAttribute(elementRef: React.RefObject<HTMLElement>, attributeName: string, value: string) { | ||
const attributeValueRef = useRef<string | undefined>(); | ||
|
||
useEffect(() => { | ||
// With this effect, we apply the attribute only on the client, to avoid hydration errors. | ||
attributeValueRef.current = value; | ||
elementRef.current?.setAttribute(attributeName, value); | ||
}, [attributeName, value, elementRef]); | ||
|
||
return { | ||
[attributeName]: attributeValueRef.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
Oops, something went wrong.