antd 动态添加表格列 表格不更新
原因:react 对比columns 数组为原数组,内存地址没变;
解决办法:用es6的扩展,生成新数组,添加操作列operateCol
setTableColumns([...tableColums,operateCol])
自定义hook enter搜索,使用方法
export const useEnterSearch = (getListFunc, dependenciesArr) => { useEffect(() => { const handleDown = (event: any) => { if (event.key == 'Enter') { getListFunc(); } }; window.addEventListener('keydown', handleDown); return () => { window.removeEventListener('keydown', handleDown); }; }, dependenciesArr); };
页面使用
useEnterSearch(getList, [searchProductVal, searchTypeVal, orgVal, accessionVal, dataSource, issueTime]);