You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@lokibai/react-store

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lokibai/react-store

state management for react

0.2.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

@lokibai/react-store

state management for react

NPM

Install

npm install --save @lokibai/react-store

Usage

// index.js
import React from 'react';
import { configureStore, Provider } from '@lokibai/react-store';
import App from './app';

const reducer = (state, action = {}) => {
	const { type } = action;

	switch (type) {
		case 'increase':
			return { ...state, count: state.count + 1 };
		case 'decrease':
			return { ...state, count: state.count - 1 };
		default:
			return state;
	}
};

const store = configureStore({reducer, preloadedState: { count: 10 });

ReactDOM.render(
	<Provider store={store}>
		<App />
	</Provider>,
	document.getElementById('root')
);
// app.js
import React from 'react';
import { useSelector, useDispatch } from '@lokibai/react-store';

const App = () => {
  const count = useSelector(state => state.count);
  const dispatch = useDispatch();

  const increase = () => {
    dispatch({ type: 'increase' });
  };

  const decrease = () => {
    dispatch({ type: 'decrease' });
  };

  return (
    <div>
      <span>{count}</span>
      <button onClick={increase}>+</button>
      <button onClick={decrease}>-</button>
    </div>
  );
};

export default App;

License

MIT ©

Keywords

react

FAQs

Package last updated on 01 Aug 2020

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