Qwerty
Qwerty

Reputation: 31959

Is it possible to change the displayName of a Context.Consumer?

How can I find my way around nested Contexts and avoid this naming hell in React Developer Tools?

Is it maybe possible to change the displayName of a Context.Consumer to give it a more, well, "context"?

What you see below is React Developer Tools showing a bunch of stacked "Context.Consumer" components, which creates a confusing view.

React developer Tools showing a bunch of stacked "Context.Consumer" components.

Upvotes: 0

Views: 2529

Answers (1)

Niki
Niki

Reputation: 1123

This works (at least on React v16.3.0+):

SomeContext.Consumer.displayName = "SomeContext.Consumer";
SomeContext.Provider.displayName = "SomeContext.Provider";

Upvotes: 2

Related Questions