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

djinn-state-react

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

djinn-state-react

djinn-state helpers for react

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Djinn-state react

npm version Build Status Codacy Badge Codacy Badge

Djinn-state helpers for react

Install

npm npm i --save djinn-state djinn-state-react

yarn yarn add djinn-state djinn-state-react

Examples

  • Todo app

Using

// djinn.js
import { Djinn, DjinnService } from 'djinn-state';
import { createUseService } from 'djinn-state-react';

export const djinn = new Djinn();
export const useService = createUseService(djinn);


// CounterService.js
export class CounterService extends DjinnService {
  state = {
    count: 0,
  };
  
  decrement = () => {
    const count = this.getState().count - 1;
    this.patch({ count });
  };
  
  increment = () => {
    const count = this.getState().count + 1;
    this.patch({ count });
  };
}

// djinnServices.js
import { djinn } from './djinn';

djinn.register(CounterService);
djinn.start();


// HomePage.js
import React from 'react';
import { useService } from './djinn';
import { CounterService } from './CounterService';

const HomePage = () => {
  const counter = useService(CounterService);
  
  return (
    <div>
    <button onClick={counter.decrement}>-</button>
    {counter.getState().count}
    <button onClick={counter.increment}>+</button>
    </div>
  );
}

export default HomePage;

Keywords

FAQs

Package last updated on 04 May 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