1 | import { useRef, createElement } from 'react';
|
2 |
|
3 | function _extends() {
|
4 | _extends = Object.assign || function (target) {
|
5 | for (var i = 1; i < arguments.length; i++) {
|
6 | var source = arguments[i];
|
7 |
|
8 | for (var key in source) {
|
9 | if (Object.prototype.hasOwnProperty.call(source, key)) {
|
10 | target[key] = source[key];
|
11 | }
|
12 | }
|
13 | }
|
14 |
|
15 | return target;
|
16 | };
|
17 |
|
18 | return _extends.apply(this, arguments);
|
19 | }
|
20 |
|
21 | function useFC(render) {
|
22 | var renderRef = useRef();
|
23 | renderRef.current = render;
|
24 | return useRef(function RenderFunctionWrapper(restProps) {
|
25 | return renderRef.current(restProps);
|
26 | }).current;
|
27 | }
|
28 | function useWith(Wrapped, props) {
|
29 | return useFC(function (restProps) {
|
30 | return createElement(Wrapped, _extends({}, props, restProps));
|
31 | });
|
32 | }
|
33 |
|
34 | export default useWith;
|
35 | export { useFC };
|
36 |
|