1 | var _require = require('react'),
|
2 | useEffect = _require.useEffect,
|
3 | useRef = _require.useRef;
|
4 |
|
5 | var UppyCore = require('@uppy/core').Uppy;
|
6 |
|
7 | module.exports = function useUppy(factory) {
|
8 | if (typeof factory !== 'function') {
|
9 | throw new TypeError('useUppy: expected a function that returns a new Uppy instance');
|
10 | }
|
11 |
|
12 | var uppy = useRef(undefined);
|
13 |
|
14 | if (uppy.current === undefined) {
|
15 | uppy.current = factory();
|
16 |
|
17 | if (!(uppy.current instanceof UppyCore)) {
|
18 | throw new TypeError("useUppy: factory function must return an Uppy instance, got " + typeof uppy.current);
|
19 | }
|
20 | }
|
21 |
|
22 | useEffect(function () {
|
23 | return function () {
|
24 | uppy.current.close();
|
25 | };
|
26 | }, []);
|
27 | return uppy.current;
|
28 | }; |
\ | No newline at end of file |