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

use-easy

v1.2.1

Published

Use Easy useEasy library for managing global state in React applications

Downloads

13

Readme

Use Easy - Unleash the Power of Simple Global State Management 🚀🌍

Streamline your global state management in React apps with our robust, user-friendly library, Use Easy.

License: MIT npm version

Use Easy is an open-source gem, designed to revolutionize global state management in React apps. It capitalizes on native browser storage technologies like LocalStorage and SessionStorage, paving the way for a global state management solution that's decoupled, lightweight, and incredibly easy to use. Let's make managing global state a breeze! 🍃

Key Features and Benefits 🔑✨

  • 🌍 Global State Management: Bid farewell to the woes of prop drilling and intricate data flow management. Effortlessly manage and share state across numerous components.

  • 📦 Storage Integration: Capitalize on your browser's native storage capabilities (LocalStorage and SessionStorage) for persistent global state.

  • 🚫 No External Dependencies: We take pride in our self-sufficiency. Use Easy doesn't rely on external libraries or frameworks, guaranteeing a lightweight and flexible state management experience.

  • ⚙️ Flexible Configuration: Tailor the global state to meet your specific needs. You can set custom group names, storage types (local or session), and keys.

  • 🔥 Advanced Actions: Execute complex operations on the global state, like resetting to the initial state, removing specific state keys, and even purging the entire state from storage.

  • 🚦 Error Handling: Handle errors seamlessly during state loading, updates, and storage operations. Customizable error messages allow for effortless debugging.

Installation 📥⚙️

Installing Use Easy is as simple as running an npm or yarn command:

npm install use-easy

# or

yarn add use-easy

Usage 🚀💡

To start using Use Easy, import the useEasy hook from the use-easy package:

import { useEasy } from 'use-easy';

Next, define your initial state and configuration options:

const initial = {
  count: 0,
};

Finally, use the useEasy hook to access the global state and advanced actions:

const MyCounter = () => {
  const { state } = useEasy({ initial })

  const handleClick = () => {
    state.count++;
  };

  const handleReset = () => {
    state.count = 0;
  };

  return (
    <div>
      <p>Count: {state.count}</p>
      <button onClick={handleClick}>Increment</button>
      <button onClick={handleReset}>Reset</button>
    </div>
  );
};

Eureka! You're now leveraging the benefits of Use Easy for managing global state in your React application! 🎉💻

Jump-Start Your Journey With Use Easy 🚀📋

To start your adventure with Use Easy in your Task Manager app, follow these simple steps:

  1. Install the Use Easy library:

    npm install use-easy
  2. Import the useEasy hook in your component:

    import { useEasy } from 'use-easy';
  3. Define your initial state and updaters:

    export const initial = {
      tasks: [],
    };
    
    export const updaters = {
      // Define your custom updaters here
      // Example:
      addTask: (state, task) => ({ ...state, tasks: [...state.tasks, task] }),
      // ...
    };
  4. Use the useEasy hook in your component:

    function App() {
      const { state, actions } = useEasy({ initial, updaters });
    
      // Use the state and actions in your component
    
      return (
        // Your component JSX
      );
    }
  5. Voilà! You're all set to manage your state with Use Easy! 🎉💼

Dive into the Pool of Actions 🏊‍♂️🚀

Use Easy equips you with a multitude of predefined actions to modify the state based on the updaters you've defined.

Here's how you can put these actions to use:

// Add a new task
actions.addTask({ id: 'unique-id', name: 'New Task', completed: false });

// Remove a task
actions.removeTask(taskId);

// Update a task
actions.updateTask(taskId, updatedTask);

Dive deep into the updaters object to explore all the ways you can play around with the tasks.

const initialState = {
  tasks: [],
};

const updaters = {
  addTask: (state, task) => ({ ...state, tasks: [...state.tasks, task] }),
  // ... your updaters
};

const App = () => {
  const { state, actions } = useEasy({ initial: initialState, updaters });

  return (
    // Your component JSX
  );
};

actions.addTask({ id: '1', name: 'New Task', completed: false });

Advanced Actions 🎩✨

Use Easy isn't just about basic actions. It empowers you with advanced actions to perform additional operations on the global state:

  • resetInitial(): Reset the global state to the current initial state.
  • onlyCurrentInitial(): Reset the global state to only the current initial state, disregarding any other changes.
  • removeState(key: string): Remove a specific state key from the global state.
  • deleteState(): Wipe out the entire global state from storage.

Error Handling 🚦🐛

In case of any errors during state loading, updates, or storage operations, Use Easy offers an error message and indicator for effortless debugging:

if (actions.isError) {
  console.log('An error occurred:', actions.errorMessage);
}

Join the Family - Contribute! 🤝❤️

We love seeing new faces in the Use Easy family! If you've found any issues or have suggestions for improvements, feel free to open an issue on our GitHub repository. And yes, pull requests are very much appreciated!

Just make sure to follow our code style, add tests for new features, and provide appropriate documentation.

License 📄

Use Easy is released under the MIT License.


Developed and maintained with love by JuanDAC. We sincerely hope Use Easy simplifies managing global state in your React applications, making your coding life a whole lot easier! 😊💻🌍