Skip to content

nainemom/use-shit

Repository files navigation

use-shit

NPM License npm bundle size

The best use-hook ever made.

Installation:

npm i use-shit

Usage

import { useShit } from 'use-shit';

const REAL_SHIT = [1, 2, 3, 4];

const [shit] = useShit(REAL_SHIT); // shit === REAL_SHIT

Example 1

import { useShit } from 'use-shit';

const REAL_SHIT = [1, 2, 3, 4];

function Component() {
  - const shit = REAL_SHIT; // ❌ It's ugly
  + const [shit] = useShit(REAL_SHIT); // ✅ Nice and smooth

  return (
    <>
      <p>Thanks god, My code is beautiful!</p>
      <ul>
        { shit.map((slice) => (
          <li key={slice}>{slice}</li>
        )) }
      </ul>
    </>
  );
}

Example 2

import { useShit } from 'use-shit';

function Component() {
  const [num1, setNum1] = useState(0);
  const [num2, setNum2] = useState(0);

  - const sum = num1 + num2; // ❌ It doesn't look good
  - const sum = useMemo(() => num1 + num2, [num1, num2]); // ❌ Unnessesury use of cache
  + const [sum] = useShit(num1 + num2); // ✅ Nice and feels right

  return (
    <>
      <input type="number" onChange={(e) => setNum1(e.target.valueAsNumber)} />
      <input type="number" onChange={(e) => setNum2(e.target.valueAsNumber)} />
      <b>{sum}</b>
    </>
  );
}

License

MIT


Static Badge