ant-design/components/_util/usePatchElement.tsx
二货机器人 d02c486052
feat: Modal support hooks (#20949)
* init hooks

* portal it in

* children with 2 context demo

* Remove config since not more second demo

* Quit with same Component for logic reuse

* add rest functions

* use localeReceiver

* use localeReceiver

* update test case

* fix lint

* update docs

* update demo title
2020-02-03 13:00:35 +08:00

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];
}