diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-05-18 11:44:37 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-05-18 11:44:37 +0200 |
| commit | 54883bb5c36cf21462a421605a709fdd6f04b150 (patch) | |
| tree | bb67a6c9ce824c52c3bae732a32f192a32969f64 /src/utils | |
| parent | f347cc1e4ae32289198d698f05f84119a708b599 (diff) | |
chore: add branding animation
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/hooks/use-styles.tsx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utils/hooks/use-styles.tsx b/src/utils/hooks/use-styles.tsx new file mode 100644 index 0000000..d47e9fb --- /dev/null +++ b/src/utils/hooks/use-styles.tsx @@ -0,0 +1,29 @@ +import { RefObject, useEffect } from 'react'; + +export type UseStylesProps = { + /** + * A property name or a CSS variable. + */ + property: string; + /** + * The styles. + */ + styles: string; + /** + * A targeted element reference. + */ + target: RefObject<HTMLElement>; +}; + +/** + * Add styles to an element using a React reference. + * + * @param {UseStylesProps} props - An object with property, styles and target. + */ +const useStyles = ({ property, styles, target }: UseStylesProps) => { + useEffect(() => { + if (target.current) target.current.style.setProperty(property, styles); + }, [property, styles, target]); +}; + +export default useStyles; |
