Files
react-native/Libraries/Core/setUpReactRefresh.js
T
Dan Abramov d7c8ace001 Replace React Transform HMR with React Refresh
Summary:
This removes React Transform HMR in favor of the new React Refresh implementation. It should only affect the "Enable Hot Reloading" mode. In further diffs I will remove "React Transform HMR" completely.

This is technically a breaking change for Metro so it'll need a version bump.

Reviewed By: rickhanlonii, rubennorte

Differential Revision: D15903585

fbshipit-source-id: 074380b00868cb31857f599a03799d3584c35d87
2019-06-21 06:04:18 -07:00

39 lines
1.1 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
if (__DEV__) {
const NativeDevSettings = require('../NativeModules/specs/NativeDevSettings')
.default;
if (typeof NativeDevSettings.reload !== 'function') {
throw new Error('Could not find the reload() implementation.');
}
if ((module: any).hot) {
// This needs to run before the renderer initializes.
const ReactRefreshRuntime = require('react-refresh/runtime');
ReactRefreshRuntime.injectIntoGlobalHook(global);
(require: any).Refresh = {
// Full Refresh
performFullRefresh() {
NativeDevSettings.reload();
},
// React Refresh
createSignatureFunctionForTransform:
ReactRefreshRuntime.createSignatureFunctionForTransform,
isLikelyComponentType: ReactRefreshRuntime.isLikelyComponentType,
register: ReactRefreshRuntime.register,
performReactRefresh: ReactRefreshRuntime.performReactRefresh,
};
}
}