跳到主要内容

React DOM client

一、作用

二、常量

1. 找到开发者工具

备注
const foundDevTools = injectIntoDevTools();

if (__DEV__) {
if (!foundDevTools && canUseDOM && window.top === window.self) {
// If we're in Chrome or Firefox, provide a download link if not installed.
// 如果我们在 Chrome 或 Firefox 中,如果未安装,则提供下载链接
if (
(navigator.userAgent.indexOf('Chrome') > -1 &&
navigator.userAgent.indexOf('Edge') === -1) ||
navigator.userAgent.indexOf('Firefox') > -1
) {
const protocol = window.location.protocol;
if (/^(https?|file):$/.test(protocol)) {
console.info(
'%cDownload the React DevTools ' +
'for a better development experience: ' +
'https://react.dev/link/react-devtools' +
(protocol === 'file:'
? '\nYou might need to use a local HTTP server (instead of file://): ' +
'https://react.dev/link/react-devtools-faq'
: ''),
'font-weight:bold',
);
}
}
}
}

三、工具

1. 嗯

全局副作用。

备注

源码中 22 - 50 行

ensureCorrectIsomorphicReactVersion();

if (__DEV__) {
if (
typeof Map !== 'function' ||
Map.prototype == null ||
typeof Map.prototype.forEach !== 'function' ||
typeof Set !== 'function' ||
Set.prototype == null ||
typeof Set.prototype.clear !== 'function' ||
typeof Set.prototype.forEach !== 'function'
) {
console.error(
'React depends on Map and Set built-in types. Make sure that you load a ' +
'polyfill in older browsers. https://react.dev/link/react-polyfills',
);
}
}

function findDOMNode(
// componentOrElement: component(...props: any),
componentOrElement: Component,
): null | Element | Text {
return findHostInstance(componentOrElement);
}

// Expose findDOMNode on internals
Internals.findDOMNode = findDOMNode;

四、转导