Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (50 sloc) 1.31 KB

Redux + Marko

See the marko-redux sample project for a fully-working example.


npm install redux --save
npm install marko --save


The partial code snippet below shows how a Marko UI component can be connected to a Redux store using the store.subscribe() method and the Marko forceUpdate() method:


import store from './store';

class {
    onMount () {
        store.subscribe(() => {
            // Force this UI component to rerender:

            // The UI component will be rerendered using the new
            // state returned by `store.getState()`
            // The following is another option to force an update:
            // this.input = store.getState();

    <counter(store.getState()) ... />


module.exports = function(state, action) {
  state = state || {
    value: 0

  // Additional reducer logic here...

  return state;

In counter.marko, the imported store module exports a Redux store created using the following code:


var redux = require("redux");
var counter = require("./reducer");

module.exports = redux.createStore(counter);