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

create-context-state

Package Overview
Dependencies
Maintainers
1
Versions
186
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-context-state

Create a context hook and provider for managing the state of your react application

  • 0.0.0-pr2222.1
  • pr2222
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26K
decreased by-7.42%
Maintainers
1
Weekly downloads
 
Created
Source

create-context-state

Manage your react state with a simple context hook creator.

Version Weekly Downloads Bundled size Typed Codebase MIT License


Installation

# yarn
yarn add create-context-state

# pnpm
pnpm add create-context-state

# npm
npm install create-context-state

Usage

Create a context and provider with built in setters and getters.

import { createContextState } from 'create-context-state';

const [CountProvider, useCount] = createContextState(({ set, get }) => ({
  defaultValue: 0,
  value: 0,
  increment: () => set((state) => ({ value: state.value + 1 })),
  decrement: () => set((state) => ({ value: state.value - 1 })),
  reset: () => get('value') !== get('defaultValue'),
}));

const App = () => {
  return (
    <CountProvider>
      <Counter />
    </CountProvider>
  );
};

const Counter = () => {
  const { value, increment, decrement, reset } = useCount();

  return (
    <>
      <span>{value}</span>
      <button onClick={() => increment()}>+</button>
      <button onClick={() => decrement()}>-</button>
      <button onClick={() => reset()}>reset</button>
    </>
  );
};

Keywords

FAQs

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