Skip to content
/ reux Public

a state management library like vuex, but used in react

Notifications You must be signed in to change notification settings

zyl1314/reux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

reux

骚操作!在react中使用vuex

Usage

  • createStore
const store = new Reux({
  state: {
    list: [{count: 1}]
  },
  mutations: {
    add (state, payload) {
      state.list.push(payload)
    }
  },
  actions: {
    add ({commit}, payload) {
      setTimeout(function() {
        commit('add', payload);
      }, 1000);
    }
  }
})
  • Provider
ReactDOM.render(
  <Provider store = {store}>
    <App />
  </Provider>,
document.getElementById('root'));
  • connect
class List extends Component {
  render() {
    const { list } = this.props;
    return (
      <ul>
        {
          list.map((i, idx) => <li key={idx}>{i.count}</li>)
        }
      </ul>
    )
  }    
}

export default connect((state) => {
  return {
    list: state.list
  }
})(List);

Examples

$ cd demos/todolist
$ npm install
$ npm start

Todo

  • 支持Module

License

MIT

About

a state management library like vuex, but used in react

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published