Intellij WebStorm 显示对封装的 React 组件的无用用法搜索(使用 HOC)
Intellij WebStorm showing useless usage search on encapsulated React components (using HOC)
基本上是this issue.
同时使用类似
的代码
class SomeComponent extends React.Component {
}
export default withRouter(SomeComponent);
我无法正确使用搜索用法,因为它显然找到了导出行。
它可以像这样在功能组件中被破解:
const SomeComponent = withRouter((props) => {
//...component here
});
export default SomeComponent;
但是在使用 redux 时变得非常难看:
const mapStateToProps = (state, ownProps) => ({
....
});
const SomeComponent = connect(mapStateToProps)({
cartPhotos,
digitals,
balancePrice,
photolabPrice,
digitalsPrice,
voucher,
photosPrice,
deliveryPrice,
totalPrice,
openPhotolabModal,
isSidebar,
}) => {
});
export default SomeComponent;
我的问题是:
- 有没有一种方法可以在不使用这种丑陋方法的情况下克服这个问题?
- 有没有办法在 class 组件上完全克服这个问题?
SomeComponent 只找到一个 ref 是正常的。
SomeComponent !== 你的默认导出
如果您右键单击默认值并在那里搜索用法,您会发现所有在导入中使用它的用法。
基本上是this issue.
同时使用类似
的代码class SomeComponent extends React.Component {
}
export default withRouter(SomeComponent);
我无法正确使用搜索用法,因为它显然找到了导出行。
它可以像这样在功能组件中被破解:
const SomeComponent = withRouter((props) => {
//...component here
});
export default SomeComponent;
但是在使用 redux 时变得非常难看:
const mapStateToProps = (state, ownProps) => ({
....
});
const SomeComponent = connect(mapStateToProps)({
cartPhotos,
digitals,
balancePrice,
photolabPrice,
digitalsPrice,
voucher,
photosPrice,
deliveryPrice,
totalPrice,
openPhotolabModal,
isSidebar,
}) => {
});
export default SomeComponent;
我的问题是:
- 有没有一种方法可以在不使用这种丑陋方法的情况下克服这个问题?
- 有没有办法在 class 组件上完全克服这个问题?
SomeComponent 只找到一个 ref 是正常的。
SomeComponent !== 你的默认导出
如果您右键单击默认值并在那里搜索用法,您会发现所有在导入中使用它的用法。