New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

el-state

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

el-state

React state management with hook

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

él-staté

React state management with hook

Usage

Please see example.

Use StoreProvider

import React from 'react';
import ReactDOM from 'react-dom';
import { StoreProvider } from 'el-state';
import App from './App';

ReactDOM.render(<StoreProvider><App /></StoreProvider>, document.getElementById('root'));

Define a store

import { createStore, createState } from 'el-state';

type CounterState = {
  counter: number;
};
const counterStore = createStore({
  initialState: createState<CounterState>({ counter: 0 }),
  actions: {
    increase(ctx) {
      // ctx.state.counter++; // => compile error: counter is readonly
      ctx.setState(state => ({ counter: state.counter + 1 }));
    },
    set(ctx, counter: number) {
      ctx.setState({ counter });
    },
    reset(ctx) {
      this.set(ctx, 0);
    },
  },
});

Use the store

const MyComononent: React.FC = () => {
  const counter = useStore(counterStore, state => state.counter);

  // use the counter
}

Call an action

const MyComononent: React.FC = () => {
  const increaseCounter = useAction(counterStore.increase);
  // use this function as onClick handle
}

Use dispatcher

const MyComononent: React.FC = () => {
  const dispatch = useDispatcher();

  const onBtnIncreasePressed = () => dispatch(counterStore.increase());
  // use this function as onClick handle
}

FAQs

Package last updated on 02 Sep 2019

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