4.0.2 • Published 4 years ago

@gunnarx2/utils v4.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

@gunnarx2/utils

npm version npm downloads npm bundle size npm license lerna

Collection of utilities. Every utility supports TypeScript and Server-side rendering.

Installation

yarn add @gunnarx2/utils

Usage

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 => {};