DEV Community

Discussion on: Let's talk about how React is only a view layer

 
cyberhck profile image
Nishchal Gautam • Edited

well, IMO, as soon as you use any of the hooks from redux, like useSelector, (honestly, we've banned them in our linting rules, so I don't even know what hooks are available from redux), but as soon as you do that, your components gets glued together with data, sure, logic is in different file, doesn't mean it's still separate, you used it in a way that I can't re-use your component without using that hook.

But again, let me reiterate, if that works for you, it's good, for me, I don't like that even one bit, when you mix your view with data, that's a problem,

when you use component, the original component is still not really glued with redux, because your connect hoc does the glueing part, which means say you don't want to use redux anymore, you can.

But as soon as you useSelector from redux, then you're stuck with redux forever, (unless you change so many places)

Also btw, I don't use redux-saga the way it's shown in example, the reason is that there's handling of dependency correctly, say you want an API client, you don't want to have to create a client in every saga file, they have recommended to use what pattern works, use just that one, I use the OOP way, here's an example:
github.com/crazyfactory/ts-react-b... (registers all sagas)
github.com/crazyfactory/ts-react-b... (base class which all sagas implement, and it makes sure we get the dependency we need)
github.com/crazyfactory/ts-react-b... (example of a saga which fetches an API call)

On that boilerplate, we're not doing Sdk, so dummyApi is being called directly, BUT, when you do have api, you define that as dependency on your BaseSaga, and a instance of sdk will be passed (I'm finishing up a project where I'll be doing this, I'll give you that link once I have it. :)

Thread Thread
 
pengeszikra profile image
Peter Vivo

You can use saga capability with useSagaReducer without redux ( I don't use redux ). In that way you can use saga same simply way as use useReducer. And you right if you put hook in any component, you can't use without that. But I think if you write your components without any outer dependency, and all date and action come from props, then your components can be reused, don't mother if you use state, or saga driven side effects inside of them.