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

redux-simple-store

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-simple-store

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

redux-simple-store

Just install the package:

npm i --save redux-simple-store

Create your store:

import { Store } from 'redux-simple-store'

export default new Store({
  count: null,
})

Now you can use your store either in class component or function component:

import React from 'react'
import ReactDOM from 'react-dom'
import store from './store'
import { useStore } from 'redux-simple-store'

const Button = ({ onClick, children }) => {
  return (
    <button onClick={onClick}>{children}</button>
  )
}

function App() {
  const count = useStore(store, state => state.count)

  useEffect(() => {
    const timer = setInterval(() => {
      store.count = store.count + 1
    }, 1000)
    return () => clearInterval(timer)
  }, [])

  return (
    <>
      {count}
      <Button onClick={() => store.count = count + 1}>inc</Button>
      <Button onClick={() => store.count = store.count - 1}>dec</Button>
    </>
  )
}

ReactDOM.render(
  <React.StrictMode>
    <App />
  </React.StrictMode>,
  document.getElementById('root')
)

In class component you need:

  componentDidMount() {
    this.unsubscribe = Store.subscribe(store, state => {
      this.forceUpdate()
    })

    // or simply
    // this.unsubscribe = Store.subscribe(store, this)
  }

  componentWillUnmount() {
    this.unsubscribe()
  }

Keywords

redux

FAQs

Package last updated on 02 May 2022

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