[英]How to extend the default behaviour of a prop of a React component?
您好,我的表格組件取自 ant 設計的表格,我想更改更改當前頁面時發生的情況。
function DefaultTable<T extends Entity>(props: TableProps<T>): JSX.Element {
const { pagination } = props;
const [currentPage, setCurrentPage] = useState(1);
const [currentPageSize, setCurrentPageSize] = useState<number>();
return (
<Form>
<Table
{...props}
pagination={
pagination !== false && {
onChange: e => setCurrentPage(e),
defaultCurrent: currentPage,
onShowSizeChange: (_current, newSize) => setCurrentPageSize(newSize),
pageSize: currentPageSize,
...pagination
}
}
/>
</Form>
);
}
但是,當我更改頁面時,過濾器、排序器和其他一些配置也消失了。 我認為是因為這個 onChange function onChange: e => setCurrentPage(e)
,默認行為被忽略。 有沒有辦法擴展默認的 onChange,然后將我當前的setCurrentPage(e)
添加到它?
我一直在查看 antd 上的Table
和Pagination
實現,沒有證據可以解釋為什么添加onChange
會阻止默認行為。
https://codesandbox.io/s/customized-filter-panel-antd4123-forked-1nwro?file=/index.js
我也一直在玩 antd 文檔提供的Table
示例,我在其中添加了一個onChange
句柄,過濾行為保持不變。
嘗試隔離代碼並提供更多信息 - 這樣我們可以更好地幫助您。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.