Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incrementAsync action in the example does not work. #126

Open
tteke opened this issue Nov 21, 2018 · 3 comments
Open

incrementAsync action in the example does not work. #126

tteke opened this issue Nov 21, 2018 · 3 comments

Comments

@tteke
Copy link

tteke commented Nov 21, 2018

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.

@indatawetrust
Copy link

@tteke
Copy link
Author

tteke commented Nov 23, 2018

I guess the problem is with the dependency versions. In the example unistore dependency version is 2.2.0 and in the one you sent its 3.1.0. So maybe version in the sandbox should also be bumped.

@kidqueb
Copy link

kidqueb commented Jan 6, 2019

import createStore from 'unistore'
import { Provider, connect } from 'unistore/preact'

createStore needs to come from unistore and Provider/connect come from its specific implementation (preact or react)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants