MCPcopy
hub / github.com/facebook/react / setSrcObject

Function setSrcObject

packages/react-dom-bindings/src/client/ReactDOMSrcObject.js:10–25  ·  view source on GitHub ↗
(domElement: Element, tag: string, value: any)

Source from the content-addressed store, hash-verified

8 */
9
10export function setSrcObject(domElement: Element, tag: string, value: any) {
11 // We optimistically create the URL regardless of object type. This lets us
12 // support cross-realms and any type that the browser supports like new types.
13 const url = URL.createObjectURL((value: any));
14 const loadEvent = tag === 'img' ? 'load' : 'loadstart';
15 const cleanUp = () => {
16 // Once the object has started loading, then it's already collected by the
17 // browser and it won't refer to it by the URL anymore so we can now revoke it.
18 URL.revokeObjectURL(url);
19 domElement.removeEventListener(loadEvent, cleanUp);
20 domElement.removeEventListener('error', cleanUp);
21 };
22 domElement.addEventListener(loadEvent, cleanUp);
23 domElement.addEventListener('error', cleanUp);
24 domElement.setAttribute('src', url);
25}

Callers 2

commitMountFunction · 0.90
setPropFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected