问题
I'm trying to install the standalone react-devtools, which by default listens to port 8097. My app uses port 3001. The documentation says the following:
"By default DevTools listen to port 8097 on localhost. If you need to customize host, port, or other settings, see the react-devtools-core package instead."
How do I go about changing the port to listen to 3001 instead?
Source: https://github.com/facebook/react-devtools/tree/master/packages/react-devtools
回答1:
The docs advise to have a look at react-devtools-core:
require('react-devtools-core').connectToDevTools(options)
This is similar to
require('react-devtools')
in another package but providing more control. Unlikerequire('react-devtools')
, it doesn't connect immediately, but exports a function.Run
connectToDevTools()
in the same context as React to set up a connection to DevTools. Make sure this runs before anyreact
,react-dom
, orreact-native
imports.The options object may contain:
- host (string), defaults to
'localhost'
.- port (number), defaults to
8097
.- resolveRNStyle (function), used by RN and
null
by default.
回答2:
You can also change your emulator or device port to 8097. Worked for me.
Eg: adb -s <device-name> reverse tcp:8097 tcp:8097
How to find device name: run adb devices
来源:https://stackoverflow.com/questions/43074677/react-devtools-by-default-devtools-listen-to-port-8097-on-localhost-how-to-cus