react-devtools: By default DevTools listen to port 8097 on localhost. How to customise?

此生再无相见时 提交于 2021-02-08 04:41:42

问题


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. Unlike require('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 any react, react-dom, or react-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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!