Sitelet https://github.com/developit/unistore/issues/126
Skip to content

incrementAsync action in the example does not work. #126

Description

@tteke
import "./style";
import { Component, render } from "preact";
import { Provider, createStore, connect } from "unistore";

let store = createStore({ count: 0 });

// If actions is a function, it gets passed the store:
let actions = store => ({
  // Actions can just return a state update:
  increment(state) {
    return { count: state.count + 1 };
  },

  // The above example as an Arrow Function:
  increment2: ({ count }) => ({ count: count + 1 }),

  // Async actions are actions that call store.setState():
  incrementAsync(state) {
    setTimeout(() => {
      store.setState({ count: state.count + 1 });
    }, 100);
  }
});

const App = connect("count", actions)(({ count, incrementAsync }) => (
  <div>
    <p>Count: {count}</p>
    <button onClick={incrementAsync}>Increment</button>
  </div>
));

render(
  <Provider store={store}>
    <App />
  </Provider>,
  document.body
);

I tried the use it in the example given like above, just changed the increment to incrementAsync but it doesnt update the state.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions