Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

igris

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

igris

A lightweight, type-safe state management solution designed to make React state simple

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
37
Maintainers
1
Weekly downloads
 
Created
Source

Igris

Build Size Version Downloads

Igris is a small, simple, and type-safe state management solution for React and React Native. It offers efficient data persistence and seamless integration with various storage mechanisms. Designed to be lightweight and intuitive, Igris helps developers manage application state with ease and confidence.

Features

  • Simple API: Straightforward and intuitive for quick setup and easy state management.
  • Type-safe: Leverages TypeScript to ensure reliable and error-resistant state management.
  • Synchronous & Asynchronous Storage: Flexible options to suit various application requirements.
  • Efficient Data Persistence: Reliable state storage across sessions for seamless user experiences.
  • Customizable Configuration: Adaptable storage and persistence options for diverse application needs.
  • Seamless Integration: Easy to adopt in existing React and React Native projects.

Installation

Install Igris using npm:

npm install igris

Or using yarn:

yarn add igris

Usage

Store Example

import React from 'react';
import { createStore, createState } from 'igris';

// Create a new instance of the store with initial state and actions
export const useCount = createStore(
  { count: 0 },
  ({ set, get }) => ({
    increment: () => set({ count: get().count + 1 }),
    decrement: () => set({ count: get().count - 1 }),
  })
);

// Component using the entire store
const CounterComponent = () => {
  const { count, decrement, increment } = useCount();

  return (
    <div>
      <p>Count: {count}</p>
      <button onClick={increment}>Increment</button>
      <button onClick={decrement}>Decrement</button>
    </div>
  );
};

// Component using a selector for state
const CountDisplayComponent = () => {
  const count = useCount((state) => state.count);
  return <p>Count: {count}</p>;
};

// Component using a selector for actions
const CountActionsComponent = () => {
  const { increment, decrement } = useCount((state) => ({
    increment: state.increment,
    decrement: state.decrement,
  }));

  return (
    <div>
      <button onClick={increment}>Increment</button>
      <button onClick={decrement}>Decrement</button>
    </div>
  );
};

State Example

export const useDarkTheme = createState(true);

const ThemeComponent = () => {
  const [isDark, setDark] = useDarkTheme();

  return (
    <div>
      <p>Current Theme: {isDark ? 'Dark' : 'Light'}</p>
      <button onClick={() => setDark(true)}>DARK</button>
      <button onClick={() => setDark(false)}>LIGHT</button>
    </div>
  );
}

API Reference

createStore(initialState, actions)

Creates a new store with the given initial state and actions.

  • initialState: An object representing the initial state of the store.
  • actions: A function that receives set and get methods and returns an object of actions.

createState(initialValue)

Creates a new state hook with the given initial value.

  • initialValue: The initial value of the state.

Advanced Usage

For comprehensive usage examples and detailed API documentation, please visit our official documentation site.

Contributing

We welcome contributions from the community! If you encounter any issues or have suggestions for improvement, please feel free to open an issue or submit a pull request on the Igris GitHub repository.

Support

If you find Igris helpful, consider supporting its development:

"Buy Me A Coffee"

Your support helps maintain and improve Igris for the entire community.

License

This project is licensed under the MIT License.


Made with ❤️ by Alok Shete

Keywords

FAQs

Package last updated on 14 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc