Skip to content

Conversation

@esamattis
Copy link
Contributor

@esamattis esamattis commented May 28, 2016

I'm using bunch of custom HOCs with connect() like

function addPostTitle(postId) {
  return connect(
    state => ({title: state.posts[postId]}),
    null, null, {name: "addPostTitle"})
  );
}

This causes React devtools to be polluted with useless Connect(Connect(Connect(Something))) style components. This would allow to use more meaningful names.

@gaearon
Copy link
Contributor

gaearon commented May 28, 2016

I think I’d rather not add a separate API for this.
You can reassign it manually, so I think this would work best.

var c = connect(...)
c.displayName = ...

@esamattis
Copy link
Contributor Author

esamattis commented May 29, 2016

I know but it gets really cumbersome if I want to have the original name in it:

function addPostTitle(postId) {
  return Component => {
    var C = connect(state => ({title: state.posts[postId]}))(Component);
    C.displayName =`addPostTitle(${getDisplayName(Component)})`;
    return C;
  };
}

Also I need to the implement the getDisplayName or add dependency which implements it.

@gaearon
Copy link
Contributor

gaearon commented May 29, 2016

OK. Let’s rename it to displayName?

@esamattis
Copy link
Contributor Author

OK. Let’s rename it to displayName?

Yeah. It's more consistent with other APIs.

@esamattis esamattis changed the title Add name option to connect() Add displayName option to connect() May 29, 2016
@esamattis
Copy link
Contributor Author

PR updated. Also added a simple test case for it.

@TigerC10
Copy link

Am I the only one that thinks that the Connect wrapper should just leverage the same displayName as the original wrapped component?

@ianobermiller (FormidableLabs/radium#271 on Jul 17, 2015)
Can you imagine if every decorator did the same thing? Radium(Relay(autobound(Button))) 👎

@timdorr
Copy link
Member

timdorr commented Aug 14, 2016

Superseded by #416

@timdorr timdorr closed this Aug 14, 2016
aikoven pushed a commit to aikoven/react-redux that referenced this pull request Nov 21, 2016
neeharv pushed a commit to neeharv/react-redux that referenced this pull request Feb 18, 2017
albertodev7 pushed a commit to albertodev7/react-redux that referenced this pull request Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants