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

kinetiq

v1.0.0-beta.2

Published

The simplest state management library for React

Downloads

151

Readme

Kinetiq

Pronunciation: /kɪˈnetɪk/ (ki-ne-tik)

Kinetiq, derived from the word "kinetic" meaning "relating to motion," embodies the concept of dynamic state management in React applications.

Kinetiq is a lightweight React library that provides simple and efficient global state management. It offers an intuitive and flexible way to handle shared state across components in functional React applications.

Features

  • Simple and intuitive API
  • Lightweight with minimal overhead
  • TypeScript support
  • Easy to integrate into existing React projects
  • Flexible global state management
  • Support for multiple independent global states

Installation

You can install Kinetiq using your preferred package manager:

npm install kinetiq

or

bun add kinetiq

Usage

Kinetiq exports two main functions that each offer different ways to manage global state.

  • useGlobal is a pre-built custom hook that takes an id and an (optional) initial value and returns a stateful value and a function to update it.
  • createGlobal is a function that takes an initial value and returns a custom hook that can be used to manage a specific global state.

useGlobal

This hook is essentially useState with a global scope. The key is necessary to map the state to a specific value regardless of where it is in the component tree.

No matter where you apply useGlobal, you need the key.

const [count, setCount] = useGlobal("count", 0)

The above snippet will initialize the global count state with a value of 0. Here is how we can use this in multiple components:

const App = () => {
    return (
        <div>
            <Button />
            <Display />
        </div>
    )
}

const Button = () => {
    const [count, setCount] = useGlobal("count", 0) // we don't really need to use the 'count' value here but we have to destructure it to get the setCount function.

    return (
        <button onClick={() => setCount((prev) => prev + 1)}>Increment</button>
    )
}

const Display = () => {
    const [count] = useGlobal("count") // Notice how we dont need to provide an initial value here.

    return <p>Count: {count}</p>
}

createGlobal

This function is essentially a smaller version of Jotai's atom function. This allows users to create their own global useState-ish hooks. Instead of a mapping approach, you export a hook from the createGlobal function and use it anywhere in your application.

// global.ts
export const useCount = createGlobal()
// App.tsx
import { useCount } from "./global" // import the hook for usage

const App = () => {
    return (
        <div>
            <Button />
            <Display />
        </div>
    )
}

const Button = () => {
    const [count, setCount] = useCount(0) // practically useState

    return (
        <button onClick={() => setCount((prev) => prev + 1)}>Increment</button>
    )
}

const Display = () => {
    const [count] = useCount() // similar to useGlobal, we don't need to provide an initial value here.

    return <p>Count: {count}</p>
}

API Reference

useGlobal<T>(key: string, initialValue?: T): [T, (newValue: T | ((prevValue: T) => T)) => void]

A hook for managing global state.

  • key: A unique string identifier for the state.
  • initialValue: An optional initial value for the state.
  • Returns: A tuple containing the current state value and a function to update it.

createGlobal<T>(): (initialValue?: T) => [T, (newValue: T | ((prevValue: T) => T)) => void]

Creates a new global state hook.

  • Returns: A custom hook for managing a specific global state.

TypeScript Support

Kinetiq is written in TypeScript and provides type definitions out of the box. No additional setup is required to use it in a TypeScript project.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Author

Making your life easier, one line of code at a time,

Cheers, Gibson Murray

Acknowledgments

  • React team for the cringetastic and unintuitive useContext API (ily guys fr)
  • All contributors and users of Kinetiq