1.0.2 • Published 3 years ago

maj-hooks v1.0.2

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

maj-hooks

Library with the hooks that I use into my projects with react.

How to use ?

  npm i maj-hooks

useRecognition hook.

import { useRecognition } from 'maj-hooks';

const MyComponent = () => {
  const [result, recognition] = useRecognition({ language: 'pt_BR' });

  useEffec(() => {
    if (result?.speech) {
      /*Do something*/
    }
  }, [result.speech]);

  const onSpeak = () => {
    const { error, isListening } = result;

    if (error) {
      /*Do something*/
    }

    isListening ? recognition.stop() : recognition.start();
  };
};

useTheme

The useTheme hook provide two options of colors ('dark', and 'light'). By default the light theme is returned in the first position of array. So, to use dark theme you need to pass true, in the function that is returned in the second position of hook.

  import { useTheme } from 'maj-hooks';

  const MyComp = () => {
    const [theme, setTheme] = useTheme();

    ...
    ...

    const onToggle = () => {
      setTheme((prev) => !prev);
    };

    return (
      <div styles={{ backgroundColor: theme }}>
        ...
      </div>
    )
  }

How to contribute ?

If there is one or more hook that you are created and you think that it can help someone else, you need now clone or fork this repo and open new pr with your feature, fix bug, chore or something else.