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

react-changes

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-changes

React-Changes is a versatile and easy-to-use state management library built for React applications. It provides an intuitive way to manage complex state with a `useChange` hook. This custom hook enables interaction with the global state either in a named

  • 0.0.9
  • npm
  • Socket score

Version published
Weekly downloads
21
decreased by-47.5%
Maintainers
1
Weekly downloads
 
Created
Source

React-Changes

React-Changes is a versatile and easy-to-use state management library built for React applications. It provides an intuitive way to manage complex state with a useChange hook. This custom hook enables interaction with the global state either in a named or unnamed manner, providing flexibility for handling simple as well as complex data sets, like multi-page forms or deeply nested properties. The library also offers versioning and playback of global state changes.

Features

  • useChange Hook: A custom React hook that provides useState-like functionality for global state. It can be used in a named manner (ideal for deeply nested state properties or complex data sets) or an unnamed manner. Both modes return a pair: an array with the current state value and a function to update that value.

  • Versioning: The library keeps track of every change made to the global state, enabling users to undo and redo changes, inspect the history of state changes, or seek to a specific version of state.

  • Playback: The library allows users to playback the history of state changes, which can be helpful for debugging or understanding user interactions.

Installation

You can install React-Changes using npm or yarn.

npm install react-changes
yarn add react-changes

Usage

First, wrap your application in the Changes (GlobalStateProvider) component.

import { Changes } from "react-changes";

function App() {
  return (
    <Changes>
      <YourComponent />
    </Changes>
  );
}

Named usage

To manage complex or nested state properties, or group related properties together, use the useChange hook in its named manner:

import { useChange } from "react-changes";

function YourComponent() {
  const [value, setValue] = useChange("group.property", "default value");

  // To update the value
  setValue("new value");

  // ...
}

Unnamed usage

If you don't need to manage deeply nested state or group related properties together, you can use the useChange hook in its unnamed manner:

import { useChange } from "react-changes";

function YourComponent() {
  const [value, setValue] = useChange("default value");

  // To update the value
  setValue("new value");

  // ...
}

In this case, the hook automatically assigns a unique, memoized string as the path to your state value.

To access the control actions for the global state, use the useChangeControls hook.

import { useChangeControls } from "react-changes";

function YourComponent() {
  const { undo, redo, play, stop, clear, versions, seek } = useChangeControls();

  // ...
}

To display buttons for controlling the global state, use the PlayerControls component.

import { PlayerControls } from "react-changes";

function YourComponent() {
  // ...
  return (
    <div>
      {/* Your component code... */}
      <PlayerControls />
    </div>
  );
}

Debugging

For debugging, you can enable the debug prop in the Changes (GlobalStateProvider) component. This will expose the global state context to the window object.

<Changes debug>{/* Your components */}</Changes>

You can then access the global state context in your browser's JavaScript console with window.gs.

Future Improvements

The library is still under development. In the future, we aim to:

  • Improve typescript support for better type safety
  • Enhance the versioning

FAQs

Package last updated on 29 May 2023

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