不想用return
    const renderEmpty = () => (
        <div style={{textAlign: 'center', cursor: 'pointer'}}>
            <div className="image-style">
                <Image
                    src={EmptyPng}
                    preview={false}
                    alt="当前还没有任务,请新建任务"
                    
                />
            </div>
            <p className="image-alt">当前还没有任务,请新建任务</p>
        </div>
    );
antd typescript报错
 
  
  
  const tableConfig = {
        columns: columns,
        dataSource: data,
        pagination: false, 
    };
如果不确定一个值的类型,用map、length怕报错的话
data?.length 
好用的前端枫叶,不用给定初次调用的默认值
const getPageData = (cur: number) => {
    const copyData = JSON.parse(JSON.stringify(data));
    const showData = copyData.slice((cur - 1) * pagesize, cur * pagesize);
    setData(data);
};
泛型数组
export interface ColoumnType<T> { 
    title: string | ReactElement,
    dataIndex: T,
    render?: (value: string) => ReactElement
}
const columns : ColoumnType<string>[] = [...]  
                                         
useRef的妙用
{
    sortRef.current = !sortRef.current;
  
  let sortData = copyAllTranslate.sort(
      creatCompare('timer', sortRef.current) 
  );
}
const [current, setCurrent] = useState<number>(1);
const getPageDatas = (cur: number) => { 
    const copyDatas = JSON.parse(JSON.stringify(data));
    if(cur === 1){
      const showData = copyDatas.slice((cur - 1) * pagesize, cur * pagesize);
      setData(data);
    }
    
    const showData = copyDatas.slice((current - 1) * pagesize, current * pagesize);
    setData(data);
};
ReactElement
ReactElement 是JSX.Element的父级,可以相互赋值(类型)。
sort排序封装
let sortData = copyAllTranslate.sort(
    creatCompare('timer', sortRef.current) 
);
const creatCompare = (propertyName: string, type: boolean) => {
    return function (obj1: GetDataType, obj2: GetDataType): number {
        let value1 = obj1[propertyName];
        let value2 = obj2[propertyName];
        return type ? value1 - value2 : value2 - value1; 
    };
};
antd组件的渲染父级别
getPopupContainer={triggerNode => triggerNode.parentNode as HTMLElement}
自定义tab
其他
antd tabel 的colmuns只要最后传给tabel就好了,写在哪本身不重要。写在父组件传给子都没问题。
表格th若是有特殊样式,一些图标对应一些操作、下拉框什么的,
可以在colmuns的title写一个函数 as ReactElement防止报错
title: getTitleIcon('任务创建时间') as ReactElement,
  
需要下拉框的,给一个 Dropdown,节点会挂在th(ant-table-cell) 上,menu的父级会与 Dropdown包裹的div同级,
而不是挂在body上,挂在body上像datav这样的框架是会出问题的。
判断数组类型
let obj = {}
undefined
obj.slice(1)
VM635410:1 Uncaught TypeError: obj.slice is not a function
at <anonymous>:1:5