是否可以更改 Context.Consumer 的显示名称?
Posted
技术标签:
【中文标题】是否可以更改 Context.Consumer 的显示名称?【英文标题】:Is it possible to change the displayName of a Context.Consumer? 【发布时间】:2018-10-12 20:05:10 【问题描述】:我怎样才能找到解决嵌套上下文的方法并避免这个地狱?
【问题讨论】:
这是怎么发生的? 好吧,到目前为止,react-devtools 中还没有办法分离出上下文显示名称,在同一 github.com/facebook/react-devtools/issues/1008 上有一个未解决的问题 【参考方案1】:这有效(至少在 React v16.3.0+ 上):
SomeContext.Consumer.displayName = "SomeContext.Consumer";
SomeContext.Provider.displayName = "SomeContext.Provider";
【讨论】:
以上是关于是否可以更改 Context.Consumer 的显示名称?的主要内容,如果未能解决你的问题,请参考以下文章