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

react-powerpack

v1.0.5

Published

react-powerpack useful components

Downloads

13

Readme

react-powerpack

react-powerpack useful components & hooks

Installation

Documentation

Documentation


Install react-powerpack with npm

  npm install react-powerpack

Usage/Examples

<Show,Each/>

import { Show, Each } from 'react-powerpack';



function App() {

  const [visible,setVisible] = useState(false)
  const [nums,setNums] = useState([0,1,2,3,4,5])

  return (
    <Show>
      <Show.When isTrue={visible}>
        <Each of={nums} render={(num, index) => 
          <div>
           render {num}
          </div>
         
        } />
      </Show.When>
      <Show.Else>
        visible is false
      </Show.Else>
    </Show>
  )
}

import { ClickOutsideComponent } from 'react-powerpack';



function App() {



  return (
    <div>
      <ClickOutsideComponent onClickOutside={() => console.log("CLICK OUTSIDE")}>
          <div onClick={() => console.log("CLICK INSIDE")} style={{ border: '2px solid black', width: 200, height: 50 }}>hello</div>
      </ClickOutsideComponent>
    </div>
  )
}

useApi

export function App() {
  let { request, data} = useApi('https://randomuser.me/api/', 'get')
  //let { request, data, error } = useApi('https://randomuser.me/api/', 'get')
  //let { request, data, error } = useApi('https://randomuser.me/api/', 'get', { useCredentials: true, authorization: { scheme: 'Bearer', token: 'YOUR_TOKEN' } })    
  return (
    <Show>
      <Show.When isTrue={data !== null}>
        {JSON.stringify(data, null, 2)}
      </Show.When>
      <Show.Else>
        <div>request error</div>
      </Show.Else>
    </Show>
      )
  }

useAsync


import {useAsync} from 'react-powerpack';

const UserComponent = () => {
 
  const fetchUserData = async () => {
   
    const response = await fetch('https://randomuser.me/api/');
    if (!response.ok) {
      throw new Error('Failed to fetch user data');
    }
    return response.json();
  };

 
  const { isLoading, error, result } = useAsync(fetchUserData, []);

  return (
    <div>
      {isLoading && <p>Loading user data...</p>}
      {error && <p>Error: {error.message}</p>}
      {userData && (
        <div>
          {result}
        </div>
      )}
    </div>
  );
};

useLastCallback



import {useLastCallback} from 'react-powerpack';
export function App() {

  const [count, setCount] = useState(0);
  
  const increment = () => {
          setCount(prevCount => prevCount + 1);
  }
  
  const lastIncrement = useLastCallback(increment);
  
  return (
          <div className='p-5 items-center border-2 rounded-xl flex'>
              <p >Count: {count}</p>
              <button variant='secondary' onClick={increment}>Increment</button>
              <button variant='secondary' onClick={lastIncrement}>Last Increment</button>
          </div>
                
    )
}


export default SearchBar;

useTimeout


import {useTimeout} from 'react-powerpack';

const MessageComponent = () => {
  const [showMessage, setShowMessage] = useState(false);

 
  const showMessageAfterDelay = () => {
    setShowMessage(true);
  };

  // Use useTimeout to show the message after 3 seconds
  useTimeout(showMessageAfterDelay, 3000);

  return (
    <div>
      {showMessage && <p>Message displayed after 3 seconds!</p>}
    </div>
  );
};

export default MessageComponent;

useDisclosure,useToggle


import {useToggle,useDisclosure} from 'react-powerpack';

const [isToggled, toggle] = useToggle(false);

const { isOpen, open, close, toggle } = useDisclosure();



  return (
    <div>

     useToggle ->
          <button onClick={toggle}>Toggle</button>
          {isToggled ? <div>Toggle is ON</div> : <div>Toggle is OFF</div>} 

      useDisclosure - >

          <div>
            <button onClick={open}>Open Modal</button>
            <button onClick={close}>Close Modal</button>
            <button onClick={toggle}>Toggle Modal</button>
            {isOpen && (
              <div style={{ border: '1px solid black', padding: '10px' }}>
                Modal content
              </div>
            )}
          </div>

    </div>
  );
};

export default MessageComponent;

List components

component | description ------------- | ------------- Show | Conditional Renderer Each | Dynamic List Renderer ClickOutsideComponent | Component for handling external clicks TextFit | AutoResizable custom text More... | Documentation

List hooks

hook | description ------------- | ------------- useApi | Custom Axios Hook useAsync | Handles asynchronous operations useLastCallback | Remembers the last callback function useTimeout | Executes a function after a delay useClickOutside | Hook for detecting clicks outside useDisclosure | Manage modal or panel visibility useToggle | Toggle boolean state useLocalStorage | Manage localStorage events More... | Documentation