marklogic-community / grove

Grove, a toolkit full of tooling, templates, and other resources that help with building UI applications on top of MarkLogic.
https://marklogic-community.github.io/grove/
Other
5 stars 1 forks source link

Adopt React Hooks and "render props" style for core components #6

Open pete-otaqui opened 5 years ago

pete-otaqui commented 5 years ago

Hi,

I've been looking at the various components here: https://project.marklogic.com/repo/projects/NACW, especially the "redux" based ones.

I'm recommending that, in the era of react 16.8+, with "hooks", that there is a cleaner pure react approach that might be a better fit. It would mean no requirement for redux, or as much configuration and plumbing to get up and running.

I've written a very simple example, querying the Github API rather than MarkLogic admittedly, here:

https://github.com/pete-otaqui/grove-hooks

As you can see in this project, there's still the clear split between "api" and "ui" components, which is great. You can hopefully also see that there are no other dependencies and the containing <App /> doesn't need any special treatment to get the <GithubSearch /> component running. Drop it in with a "render props" style child, and away you go.

Hope this is of interest.

patrickmcelwee commented 5 years ago

Pete, I don't have the time I want to dig into this at the moment, but I just wanted to say thanks for this, and I look forward to taking a much closer look.

I totally agree that hooks like useState() provide a wonderful interface, and that it can be helpful with the kinds of things you might reach for Redux for. One reason for keeping Redux is that we may support Angular UIs in the future - having a Redux layer with a good amount of business logic in it could allow us to reuse that logic in an Angular app as well. (We've had success with Angular + Redux in the past.) Whereas migrating it all to hooks means we've put it all into React, and can't get the logic back out.

And maybe there's some advantage to using both. I haven't looked yet at whether useState() and Redux play well together.

Anyway, mostly just wanted to let you know that we saw this and it is great! Hopefully, I can engage more substantively very soon.