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

question: middleground between smart and dumb components? #735

Closed
jokeyrhyme opened this issue Sep 16, 2015 · 4 comments
Closed

question: middleground between smart and dumb components? #735

jokeyrhyme opened this issue Sep 16, 2015 · 4 comments
Labels

Comments

@jokeyrhyme
Copy link

I have a side project that features lots of components and the highest level of user interaction I've tried so far in a redux project. I'm trying to level myself up in terms of redux, and now I'm in a pickle.

I'm looked at #134, #419, #475, and @timbur's intriguing #419 (comment)

One idea briefly floated around the Slack channel was passing dispatch down from container / smart components to some smart-ish components. You don't pass it all the way down, just far enough to help limit the amount of actionCreator / eventHandler props that would otherwise be necessary.

In my case, the leaf components in my tree are still purely dumb, but some of the intermediate components are smart-ish. For me, these have been quite app-specific, and wouldn't have been very useful in other projects anyway, so trading portability for reduced boilerplate in these cases seemed like a worthy compromise.

So I've ended up with 3 types of components:

  • smart "container" components
    • use connect(), dispatch() and actionCreators
    • pass dispatch down to smart-ish components
    • pass eventHandlers down to dumb components
  • smart-ish components
    • use dispatch() and actionCreators
    • pass eventHandlers down to dumb components
  • dumb components
    • only render and call provided eventHandler methods

My main problem with strictly having smart and dumb components is that so many methods need to be explicitly passed from the nearest smart component all the way down to a dumb component. For interaction-rich components, this becomes tedious.

The question I'm asking is: am I making a huge mistake with this approach? Does this sacrifice too much (simplicity, best-practices, testability, etc) in order to gain too little (less boilerplate, less code)?

@jokeyrhyme
Copy link
Author

Also, my smart-ish components directly import and use actionCreators, instead of receiving them from parent smart components via props.

@ghost
Copy link

ghost commented Sep 16, 2015

I'll try to create react-redux-providers some time this week. Meant to do it sooner but I've been super busy. It should actually be pretty quick to put together since nearly all of it is already done. There are a couple of minor (but necessary) improvements from my original comment though. :)

@gaearon
Copy link
Contributor

gaearon commented Oct 5, 2015

Use whatever pattern works best for your apps.
You are in a better position than us to judge what works and what doesn't.
Closing as a duplicate of #419.

@gaearon gaearon closed this as completed Oct 5, 2015
@ghost
Copy link

ghost commented Oct 19, 2015

@jokeyrhyme see #419 (comment).

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

No branches or pull requests

2 participants