1 | var nullRefObject = {
|
2 | current: null // A map of created ref objects to provide memoization.
|
3 |
|
4 | };
|
5 | var refObjects = new WeakMap();
|
6 | /** Creates a React ref object from existing DOM node. */
|
7 |
|
8 | var toRefObject = function toRefObject(node) {
|
9 | // A "null" is not valid key for a WeakMap
|
10 | if (node === null) {
|
11 | return nullRefObject;
|
12 | }
|
13 |
|
14 | if (refObjects.has(node)) {
|
15 | return refObjects.get(node);
|
16 | }
|
17 |
|
18 | var refObject = {
|
19 | current: node
|
20 | };
|
21 | refObjects.set(node, refObject);
|
22 | return refObject;
|
23 | };
|
24 |
|
25 | export default toRefObject; |
\ | No newline at end of file |