npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mozeyinedu/hooks-lab

v7.0.3

Published

hooks-lab is a react package that houses several react hooks such as useSnap, useToggle etc.

Downloads

109

Readme

Descriptions

hooks-lab is a react package that houses several react hooks such as useSnap, useToggle etc.

Installation

    npm i @mozeyinedu/hooks-lab

useSnap

  • useSnap is the first hooks created in hooks-lab. It is used to add snap on a custom button (flash of opacity of on a custom button when the button is clicked)
  • It receives an optional argument to set the opacity. If no argument is specified, the default is 0.4
  • It returns a snap function which binds the button to the useSnap hook
  • The div should be styled as a real button for this functionality to become visible
  import { useSnap } from '@mozeyinedu/hooks-lab';

    
  function App() {
    const { snap } = useSnap(.5);
  
    return (
      <>
        <div style={style} {...snap() }>Click Me</div> { /* this line uses .5 as specified above, not a default */ }
        <div style={style} {...useSnap(.9).snap() }>Click Me</div>
      </>
        
        
    );
  }

  export default App;

  const style={
    padding: '8px',
    border: '1px solid',
    display: 'inline-block',
    background:'teal',
    color: '#fff',
    cursor: 'default',
    userSelect: 'none'
  }

  function App() {
    const { snap } = useSnap();
  
    return (
      <>
        <div style={style} {...snap() }>Click Me</div> { /* this line uses .4, the default */ }
        <div style={style} {...useSnap(.9).snap() }>Click Me</div>
      </>
    );
  }

  export default App;

useToggle

  • useToggle is the second hook created in hooks-lab. it returns toggleState and toggle.
  • toggleState is a boolean which can either be true or false.
  • toggle is a function that changes toggleState from true to false and vice versa.
  • Initially, toggleState is true, when toggle is executed (toggle()), it changes toggleState from true to false an saved in the local storage, when toggle is executed again, toggleState changes from false to true in the local storage. toggleState will continue to be in the local storage until manually deleted.
Use cases of useToggle hook
  • Can be used to toggle between drak and light theme in react web apps, or react native applications
  • Can be used for whatever you want to toggle and tract the toggle state in local storage
Example
import { useToggle } from '@mozeyinedu/hooks-lab';

function App() {
    const { toggle, toggleState } = useToggle();

    const style = {
        width: '300px',
        height: '300px',
        border: '1px solid',
        transition: 'all .3s',
        background: toggleState ? "#dfdfdf" : '#555',
        color: toggleState ? "#000" : '#fff'
    };
    
    return (
        <div onClick={toggle} style={style}>{toggleState ? 'Dark Theme' : 'Light Theme'}</div>
        
    );
}

export default App;

Version > 5.0.3

useToggle

import { useToggle } from '@mozeyinedu/hooks-lab';

function App() {
    const [ toggle, useToggle ] = useToggle();

    const style = {
        width: '300px',
        height: '300px',
        border: '1px solid',
        transition: 'all .3s',
        background: toggle ? "#dfdfdf" : '#555',
        color: toggle ? "#000" : '#fff'
    };
    
    return (
        <div onClick={useToggle} style={style}>{toggle ? 'Dark Theme' : 'Light Theme'}</div>
        
    );
}

export default App;

useTheme

To implement dark/light theme

  import { useTheme } from '@mozeyinedu/hooks-lab';

   const themColors = {
      light: {bg: '#fff', text: '#000'},
      dark: {bg: '#000', text: '#fff'}
  }

  function App() {
      const [colors, setColors] = useTheme({ light: themeColors.light, dark: themeColors.dark })
      return (
          <div onClick={setColors} style={{background: colors.bg, color: colors.text}}</div>
          
      );
  }

export default App;