New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@brainstack/state

Package Overview
Dependencies
Maintainers
0
Versions
154
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brainstack/state

A Micro State Management

latest
npmnpm
Version
1.1.159
Version published
Weekly downloads
112
11100%
Maintainers
0
Weekly downloads
 
Created
Source

@brainstack/state
A module for managing application state.

Installation

To install this module, run the following command:

npm install @brainstack/state

Usage

To use this module, import the createState function and the State interface from the module:

import { createState, State } from '@brainstack/state';

interface AppState {
  count: number;
}

const initialState: AppState = {
  count: 0,
};

const state: State<AppState> = createState(initialState);

state.mutate(currentState => {
  return { ...currentState, count: currentState.count + 1 };
});

console.log(state.getState());

API

createState(initialState: T): State Creates a new state instance with the given initial state.

Arguments

initialState - The initial state of the application. Returns

A State object with the getState and mutate functions.

State A interface that represents the state management module for managing application state.

Properties

getState(selector?: (state: T) => any): any - Retrieves the current state of the application.
selector (optional) - An optional selector function to retrieve a specific value from the state.
mutate(mutator: (currentState: T) => T): T - Mutates the state of the application.

Contributing

Contributions are welcome! If you would like to contribute to this module, please follow these guidelines:

Fork the repository
Create a new branch for your changes
Make your changes and commit them with descriptive commit messages
Push your changes to your fork
Submit a pull request

License

This module is released under the MIT License.

Keywords

brainstack

FAQs

Package last updated on 11 Dec 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