简体   繁体   English

Intellij WebStorm 在封装的 React 组件上显示无用的使用搜索(使用 HOC)

[英]Intellij WebStorm showing useless usage search on encapsulated React components (using HOC)

It is basically this issue .基本上就是这个问题

While using code like在使用代码时

class SomeComponent extends React.Component {

}

export default withRouter(SomeComponent);

I can't use search usages properly, because it obviously finds the export line.我无法正确使用搜索用法,因为它显然找到了导出行。

It can be hacked in functional components like this:它可以在功能组件中被黑客入侵,如下所示:

const SomeComponent = withRouter((props) => {
   //...component here
});
export default SomeComponent;

but gets very ugly when using redux for example:但是在使用 redux 时变得非常难看,例如:

const mapStateToProps = (state, ownProps) => ({
    ....
});

const SomeComponent = connect(mapStateToProps)({
    cartPhotos,
    digitals,
    balancePrice,
    photolabPrice,
    digitalsPrice,
    voucher,
    photosPrice,
    deliveryPrice,
    totalPrice,
    openPhotolabModal,
    isSidebar,
}) => {

});
export default SomeComponent;

My questions are:我的问题是:

  • Is there a way to overcome this without using such ugly approach?有没有办法在不使用这种丑陋方法的情况下克服这个问题?
  • Is there a way to overcome this on a class component AT ALL?有没有办法在类组件上克服这个问题?

It's normal that you find only one ref for SomeComponent.您只找到 SomeComponent 的一个 ref 是正常的。

SomeComponent !== your default export SomeComponent !== 您的默认导出

If you press right click on default and search there usages you find all that use it in import.如果您按右键单击默认值并在那里搜索用法,您会发现在导入中使用它的所有内容。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM