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

rehookt

v1.5.2

Published

Helps to create hooks (value+set) in an object to pass through components nodes in one go.

Downloads

4

Readme

npm version Build Status Coverage Status JavaScript Style Guide: Good Parts License: MIT

Getting started

  1. Install the package into your react js project.
    $ npm i rehookt
  2. Then in any component, just require and call useStates :
    // --- Parent component ---
    
    import ChildComponent1 from "../bar/foo/ChildComponentFolder1";
    import ChildComponent2 = from "../bar/foo/ChildComponentFolder2";
    import ChildComponentN = from "../bar/foo/ChildComponentFolderN";
    
    const { useStates, generate } = require( "rehookt" );
    
    module.exports = () => {
    
        // Generate hooks.
    
        const hooks = useStates( "first", "second", "third", "fourth", /*...*/ );
    
        // Pass the hooks object to children
       
        return (<div>
            <ChildComponent1 hooks={hooks} />
            <ChildComponent2 hooks={hooks} />
            ...
            ...
            <ChildComponentN hooks={hooks} />
        </div>)
    }
  3. In any child component, use hooks as if every hook is defined by a set method and a get property :
    // --- Any child component ---
    
    import GrandChildComponent from "../bar/baz/GrandChildComponentFolder";
       
    module.exports = ( hooks ) => {
    
        const { first, second, third, fourth, /*...*/ } = hooks;
    
        // printing the 'first' state or hook value
        console.log(first.val);
    
        // set the second state 
        const TWO = 8/4;
        third.set(TWO);
    
        // manage the 'third' state in a custom function
        bar.foo(third);
    
        return (<GrandChildComponent hooks={hooks} />)
    }

Define with a value

You can associate a value to the hook by three ways.

  1. Dont provide any value, but just the name of the hook. It will set the value to undefined by default.
    const hooks = useStates( "first", /*...*/ );
  2. Provide a 2-cells-array with the name, then the value.
    const hooks = useStates( ["first",1], /*...*/ );
  3. Provide an object.
    const hooks = useStates( {name:"first", value:1}, /*...*/ );

Special hooks

  1. rehookt_none If you wish to return an empty set of hooks, create the single Special hook identified by, REHOOKT_NONE or rehookt_none. The case is not sensitive. and the value is ignored.

    This is the only way to get an empty set... nothing given to useStates throws an exception

    const hooks1 = useStates( "rehookt_none" );
       
    // OR an object with or without a value
    const hooks2 = useStates( { name : "rehookt_none", value : "data" }, );
       
    // OR an array with or without a value
    const hooks3 = useStates( ["rehookt_none", 'none'], );
    
    console.log( hooks1, hooks2, hooks3 )
    // Will output { } { } { }

    Note: This special hook has to be the single one defined.

  2. rehookt_x REHOOKT_X or rehookt_x can help you to create generic hooks. These will have an identificant based on a formula given f(x).

       
    // Do you wish to generate hooks with the sub identifier staring from 1 ?
    const hooks1 = useStates( [ "rehookt_x",{x : 1, n : 10 , f: (x) =>{
        return x ;
      }}] );
       
    // Or do you wish to generate hooks with the sub identifier staring 
    // from 10 going by steps of 10 ?
    const hooks2 = useStates( [ "rehookt_x",{x : 10, n : 10 , f: (x) =>{
        return x * 10 ;
      }}] );
       
    // OR do you prefer playing with trigonometry ?
    const hooks3 = useStates( [ "rehookt_x",{x : 1, n : 10 , f: (x) =>{
        return x + Math.sin(x) ;
      }}] );
       
    // . . .

Github

  1. Code Visit the github test repository page Here.

  2. Demo Here is a demo project to see how you can use Rehookt how it can perform with auto generated hooks.