Comments (10)
Hey @makinde, thanks for the feedback.
No, classes don't support hooks. So the reason why I want to go all-in into hooks only API is:
- That's where React itself is going
- I don't think that having two ways of doing the same thing is beneficial. Because you'll have more API to learn, more code to maintain and bigger bundle size
I'm already building some experiments to drop support with Connect/connect and go all-in into hooks. And maybe even rebranding the project.
from redux-zero.
@Kiho @leobetosouza @malbernaz @emilianox @d3x7r0
from redux-zero.
i dont have any opinion about it. i'm almost 2 years without using the lib.
from redux-zero.
I've been away from working on much js for the last 6 months or so, so I haven't had much time to stress test the hooks but I think re-focusing on hooks is a good idea. Of course I may be biased since I'm hooked on hooks (pun 100% intended).
Anyway I'm not sure removing the Connect HOC is necessary. It would be relatively simple to refactor them to use Hooks I think.
const connect = ({ mapToProps, actions }) => (Component) => (props) => {
const selected = useSelector(mapToProps)
for (const [name, action] of Object.values(actions)) {
selected[name] = useAction(action)
}
return <Component {...props} {...selected} />
}
(untested, back of the napkin implementation).
from redux-zero.
Is a great idea, the only thing I thinking of is not breaking back-compatibility
Maybe a non-hook mode?
Or at least a breaking code warning in the update
from redux-zero.
@leobetosouza thank you for your candid feedback
@d3x7r0 how are you using useAction
with async operators? The only way I could was to do this:
const { setState } = useStore();
const incrementAsync = useAction(({ count }) => {
setTimeout(() => {
setState({ count: count + 1 });
}, 1000);
});
But I had some typing errors (when I tried using it with TypeScript).
@emilianox that makes sense as well. But to be honest, people are already getting those warnings if they're using connect
or Connect
with React >= 16.2.0. My idea was to ship a redux-zero version 6.0.0 without those functions, only focused on hooks.
And maybe even rebranding the name, since we won't have anything to redux anymore, to something else.
from redux-zero.
@matheusml wouldn't the action still support returning a promise for async tasks? You would still do something like your example if you needed to increment a loading counter for example but for simple things it should work no?
const incrementAsync = useAction(({ count }) => {
return new Promise(resolve => {
setTimeout(() => {
resolve({ count: count + 1 });
}, 1000);
})
});
Anyway I was never very happy with the useAction hook I'll admit. It feels like the function should get the store as a param at the very least but I haven't actually worked with the lib for 6 months or so like I mentioned before.
from redux-zero.
The issue with this current API (the useAction with async), is that you can't do stuff like this:
const actions = (store) => ({
getUsers: state => {
store.setState({ loading: true });
fetchUsers().then(users => {
store.setState({ users, loading: false });
});
}
});
Well, at least I tried and couldn't do it.
from redux-zero.
@matheusml interesting idea.
I use both hooks and the connect function right now. The connect function is nice for when I have a few bits of data that I need to pull out from state. Using useSelector
I have to have a separate call for each bit of data I want.
I also find it nice that the general API here is similar to redux. When other collaborate on my project, if they have used redux before, they understand mostly how to use redux-zero. If the paths diverge, that advantage goes away.
It is a bit odd to have two ways to do the same things, but I’d really encourage both to remain if possible. Also (I’m not sure) do class components support hooks?
from redux-zero.
Thanks for responding. You should definitely feel empowered to direct things as you see best.
I’ll just quickly highlight some of what you gain with the current “redux-like” branding and messaging. Because I know that this library is supposed to be like redux, I can depend on their docs. For instance, I’m trying to learn middleware in redux-zero right now. The docs are...brief, to say the least. But because it is so similar to the redux concept, I can rely on the tons of documents and blog posts about the topic.
Just something to keep in mind as you consider diverging from redux in the future. Thanks for all the hard work on the tool!
from redux-zero.
Related Issues (20)
- redux devtools dispatch not working HOT 2
- Adding redux-devtools options parameters HOT 1
- Writing typesafe actions HOT 1
- Unit mapToProps? (pass through) HOT 1
- Release seems to be missing types/Actions.ts HOT 5
- Use via script tags? HOT 1
- react waning for <Connect> HOT 11
- Not able to use redux-zero through UMD HOT 1
- Action type doesn't support Promise as return type HOT 1
- Add useActions hook for react HOT 2
- Update connect/Connect to use hooks instead of classes
- How to ensure the sequence of the async actions? HOT 2
- where is getActions exported from? HOT 1
- Proper syntax for store.setState callback?
- Docs website down?
- The latest published `types/Actions.d.ts` is not same as `types/index.d.ts` . HOT 2
- value from props is not passing
- use redux-zero in typescript HOT 1
- Can't test redux-zero with JEST and TypeScript? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-zero.