react-simple-ctx-store
v0.0.3
Published
Simple context store for react
Downloads
2
Readme
Simple React Context Store
Based on store objects and actions, draws part of concept from redux but it's much more simpler and more pleasant to use :)
README in progress!
installation:
npm i -P react-simple-ctx-store
Some examples:
import React, { Component } from 'react';
import { createStore, combineStores } from './createStore';
const store = combineStores({
name: 'myStore',
state : {
counter: 0
},
actions : {
increaseCounter({state}){
return { counter: state.myStore.counter + 1 };
}
}
})
const {
Provider,
Connect,
connect
} = createStore(store);
const App = (
<Provider>
<h2>My App</h2>
<Connect select={state => ({c : state.myStore.counter})}>
{({ c }, { increaseCounter }) => {
return (
<button onClick={increaseCounter}>
Add 1 to {c}
</button>
)
}}
</Connect>
</Provider>
);
ReactDOM.render(<App />, document.getElementById('root'));