ESLint & React
ESLint & React
eslint error && findDOMNode
error Do not use findDOMNode react/no-find-dom-node
https://stackoverflow.com/questions/40499267/react-dnd-avoid-using-finddomnode
bug
solution & not ReactDOM.findDOMNode
ESLint solution
import React,{
Component,
// useRef,
// useState,
// useEffect,
} from 'react';
import { connect } from 'dva';
import './index.less';
import { compareNextAndThisProps } from '../../../utils/pageUtils';
import { Header } from "./Header";
import { GoToTop } from "./GoToTop";
import { IndicatorCards } from "./IndicatorCards";
import { TrendingView } from "./TrendingView";
import { ChannelDistribution } from "./ChannelDistribution";
import { DeviceTypeDistribution } from "./DeviceTypeDistribution";
import { RegionDistribution } from "./RegionDistribution";
import {
Row,
Col,
Divider,
} from "antd";
const mapStateToProps = ({ mirrorHeader, dashboard }) => ({
activeTypeId: mirrorHeader?.activeTypeId,
activeVersion: dashboard?.activeVersion,
activeOs: dashboard?.activeOs,
dashboard,
});
@connect(mapStateToProps)
class Overview extends Component {
constructor(props) {
super(props);
this.state = {
updatePropsLock: false,
};
}
componentDidMount() {
this.initData();
setTimeout(() => {
this.unlockProps();
}, 1000);
this.gototopRefNode.addEventListener(`click`, (e) => {
this.dashboardOverviewRefNode.scroll({
top: 0,
left: 0,
behavior: 'smooth',
});
setTimeout(() => {
if(this.gototopRefNode){
this.gototopRefNode.style.display = "none";
}
}, 1000);
});
this.dashboardOverviewRefNode.addEventListener(`scroll`, (e) => {
const scrollTop = e.target.scrollTop;
if(scrollTop > 700){
this.gototopRefNode.style.display = "block";
} else {
this.gototopRefNode.style.display = "none";
}
});
}
componentWillReceiveProps(nextProps) {
const {
updatePropsLock,
} = this.state;
if(updatePropsLock) {
const {
appIdIsNotEqual,
osIsNotEqual,
versionIsNotEqual,
} = compareNextAndThisProps({
nextProps,
props: this.props,
});
if (appIdIsNotEqual || osIsNotEqual || versionIsNotEqual) {
this.initData();
};
}
}
unlockProps = () => {
this.setState({
updatePropsLock: true,
});
};
initData = () => {
const {
dispatch,
} = this.props;
dispatch({
type: 'dashboard/fetchIndicatorsData',
});
dispatch({
type: 'dashboard/fetchTrendData',
});
dispatch({
type: 'dashboard/fetchChannelAndDeviceData',
});
dispatch({
type: 'dashboard/fetchRegionData',
payload: {
code: 'all',
},
});
};
render() {
const {
dashboard: {
indicatorsData: indicator_datas,
},
} = this.props;
return(
<>
<Header initData={this.initData} />
<div
ref={node => this.dashboardOverviewRefNode = node}
className="dashboard-overview"
>
<Row>
<Divider className="divider-line" />
<Col span={24} className="user-indicator">
<IndicatorCards datas={indicator_datas} />
</Col>
<Col span={24} className="trending-chart">
<TrendingView />
</Col>
<Col span={12} className="channel-distribution">
<ChannelDistribution />
</Col>
<Col span={12} className="device-type-distribution">
<DeviceTypeDistribution />
</Col>
<Col span={24} className="rigion-distribution">
<RegionDistribution />
</Col>
</Row>
</div>
<GoToTop
gototopRef={node => this.gototopRefNode = node}
/>
</>
);
}
}
export default Overview;
import React, {
Component,
// useRef,
// useState,
// useEffect,
} from 'react';
class GoToTop extends Component {
constructor(props){
super(props);
this.state = {
text: "回到顶部",
};
}
render() {
const {
text,
} = this.state;
const {
gototopRef,
} = this.props;
return(
<div className="go-to-top" ref={gototopRef}>
<div
className="go-to-top-box">
<span className="go-to-top-text">{text}</span>
</div>
</div>
);
}
}
export {
GoToTop,
};
export default GoToTop;
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/11834731.html
未经授权禁止转载,违者必究!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· .NET10 - 预览版1新功能体验(一)
2015-11-11 HTML5+CSS3 animation/keyframe/transform/transition/2D translate/3D translate 学习总结
2015-11-11 IT-ebooks free download website & IT 电子书籍免费下载网站
2015-11-11 online QRcode generator , QRcode=== (Quick Response Code) , 二维条码,二维码,彩色二维码,图片二维码,