-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
Side effects / async actions #1
Comments
+1 for name it effects |
@hiddenboox My only problem with
I'm more inclined to use |
You guys might wanna check out Rematch (2.8k stars) https://github.com/rematch/rematch/blob/master/docs/purpose.md For async methods, just do your regular async/await on it : https://github.com/rematch/rematch#step-2-models |
Thank you, @joshuaquek. I'd already taken a look at Rematch before. Never used it though. It looks like a good solution for people who are using Redux. Constate has a different purpose. It's not intended to be a replacement for Redux. The problem is that people are using Redux for everything, even when they might not need it, making their projects unnecessarily complex upfront. And I had done that myself. I built Constate to fill that void in cases when you don't need Redux, MobX (or Rematch). It's not even supposed to be the only solution for state management within a single project. People can combine it with other solutions. In the end, it's just a component ( I know you're bringing it up just as a reference, not for comparison, but I wanted to share my thoughts 😄 That said, it's good to know that they use |
Another possible API is to pass const actions = {
setData: data => () => ({ data }),
setError: error => () => ({ error })
};
const effects = {
createPost: payload => async ({ setData, setError }) => {
try {
const data = await api.post('/posts', payload);
setData(data);
} catch (error) {
setError(error);
}
}
}; Its more verbose though. |
i suggest |
|
what about |
Opened a PR (#8) adding |
I'm thinking on a way to handle side effects and/or async actions on constate. This is how I'm currently planning to use it:
Possible names:
The text was updated successfully, but these errors were encountered: