mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-16 01:41:02 +08:00
19 lines
501 B
TypeScript
19 lines
501 B
TypeScript
|
import * as React from 'react';
|
||
|
|
||
|
export default function usePatchElement(): [
|
||
|
React.ReactElement[],
|
||
|
(element: React.ReactElement) => Function,
|
||
|
] {
|
||
|
const [elements, setElements] = React.useState<React.ReactElement[]>([]);
|
||
|
|
||
|
function patchElement(element: React.ReactElement) {
|
||
|
setElements(originElements => [...originElements, element]);
|
||
|
|
||
|
return () => {
|
||
|
setElements(originElements => originElements.filter(ele => ele !== element));
|
||
|
};
|
||
|
}
|
||
|
|
||
|
return [elements, patchElement];
|
||
|
}
|