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 simplifies the state management process by providing a `useChange` hook, a powerful custom hook for interacting with the global state. This hook can be

  • 0.2.0
  • latest
  • 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 simplifies the state management process by providing a useChange hook, a powerful custom hook for interacting with the global state. This hook can be used in a named or unnamed manner, and the library also provides versioning and playback capabilities for your global state changes.

Features

  • useChange Hook: This is a custom React hook that behaves like the built-in useState hook. It can be used in a named or unnamed manner. In both cases, it returns a pair, an array with the current state value and a function to update that value.

  • Nested State Access: The named usage of useChange is particularly useful for accessing nested state properties. It's ideal for managing multi-page forms, more complicated data sets, or grouping related properties together.

  • Versioning: Every change to the global state is stored as a unique version, making it possible to undo and redo changes, view the history of changes, or seek to a specific version.

  • Playback: You can export the user's entire experience and reload it for playback. This feature is beneficial for running exact tests during QA (Quality Acceptance) or for quality assurance purposes.

Installation

Use npm or yarn to install the package.

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

When you want to assign a specific name (path) to your state value, you can use the useChange hook as follows:

import { useChange } from "react-changes";

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

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

  // ...
}

The named usage of useChange is particularly useful for accessing nested state properties. For example, you can use it to manage multi-page forms or group related properties together.

Unnamed usage

To access a global state without providing a name (path), you can use the useChange hook as follows:

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 */}
</

FAQs

Package last updated on 02 Jul 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