4.0.2 • Published 4 years ago
@gunnarx2/utils v4.0.2
@gunnarx2/utils
Collection of utilities. Every utility supports TypeScript and Server-side rendering.
Installation
yarn add @gunnarx2/utils
Usage
- isSSR - Server-side rendering
- getRefElement() - Get ref element
Server-side rendering
Example - Server-side rendering
import { isSSR } from '@gunnarx2/utils';
if (isSSR) {
console.log('SSR in action 🔥');
}
Reference - Server-side rendering
Will return a boolean that indicates if Server-side rendering is present.
const isSSR: boolean = {};
Get ref element
Example - Get ref element
import React, { useRef } from 'react';
import { getRefElement } from '@gunnarx2/utils';
const Component = () => {
const ref = useRef(null);
useEffect(() => {
console.log(getRefElement(ref));
}, []);
return (
<div ref={ref} />
);
};
export default Component;
Reference - Get ref element
Will return element from ref. If it isn't wrapped in a ref it will return itself.
const getRefElement = <T>(
element?: RefObject<Element> | T
): Element | T | undefined | null => {};