Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Beta]: docs(cn): react-developer-tools.md #644

Merged
merged 3 commits into from
May 27, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions beta/src/pages/learn/react-developer-tools.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
---
title: React Developer Tools
title: React 开发者工具
translators:
- dahui4dev
---

<Intro>

Use React Developer Tools to inspect React [components](/learn/your-first-component), edit [props](/learn/passing-props-to-a-component) and [state](/learn/state-a-components-memory), and identify performance problems.
使用 React 开发者工具检查 React [components](/learn/your-first-component),编辑 [props](/learn/passing-props-to-a-component) [state](/learn/state-a-components-memory),并识别性能问题。

</Intro>

## Browser extension
## 浏览器扩展 {#browser-extension}

The easiest way to debug websites built with React is to install the React Developer Tools browser extension. It is available for several popular browsers:
调试 React 构建的网站最简单的办法就是安装 React 开发者工具浏览器扩展。它可用于几种流行的浏览器:
dahui4dev marked this conversation as resolved.
Show resolved Hide resolved

* [Install for **Chrome**](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
* [Install for **Firefox**](https://addons.mozilla.org/en-US/firefox/addon/react-devtools/)
* [Install for **Edge**](https://microsoftedge.microsoft.com/addons/detail/react-developer-tools/gpphkfbcpidddadnkolkpfckpihlkkil)
* [安装 **Chrome** 扩展](https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en)
* [安装 **Firefox** 扩展](https://addons.mozilla.org/en-US/firefox/addon/react-devtools/)
* [安装 **Edge** 扩展](https://microsoftedge.microsoft.com/addons/detail/react-developer-tools/gpphkfbcpidddadnkolkpfckpihlkkil)

Now, if you visit a website **built with React**, you will see the _Components_ and _Profiler_ panels.
现在,如果你访问一个用 **React 构建** 的网站,你将看到 _Components_ _Profiler_ 面板。

![React Developer Tools extension](/images/docs/react-devtools-extension.png)

### Safari and other browsers
For other browsers (for example, Safari), install the [`react-devtools`](https://www.npmjs.com/package/react-devtools) npm package:
### Safari 和其他浏览器 {#safari-and-other-browsers}
为其他浏览器(比如,Safari),安装 [`react-devtools`](https://www.npmjs.com/package/react-devtools) npm :
```bash
# Yarn
yarn global add react-devtools
Expand All @@ -30,26 +32,26 @@ yarn global add react-devtools
npm install -g react-devtools
```

Next open the developer tools from the terminal:
接下来从终端打开开发者工具:
```bash
react-devtools
```

Then connect your website by adding the following `<script>` tag to the beginning of your website's `<head>`:
然后通过将以下 `<script>` 标签添加到你网站的 `<head>` 开头来连接你的网站:
```html {3}
<html>
<head>
<script src="http://localhost:8097"></script>
```

Reload your website in the browser now to view it in developer tools.
现在在浏览器里刷新你的网站,你可以在开发者工具里查看它。
dahui4dev marked this conversation as resolved.
Show resolved Hide resolved

![React Developer Tools standalone](/images/docs/react-devtools-standalone.png)

## Mobile (React Native)
React Developer Tools can be used to inspect apps built with [React Native](https://reactnative.dev/) as well.
## 移动端(React Native){#mobile-react-native}
React 开发者工具同样可检查用 [React Native](https://reactnative.dev/) 构建的应用程序。
dahui4dev marked this conversation as resolved.
Show resolved Hide resolved

The easiest way to use React Developer Tools is to install it globally:
使用 React 开发者工具最简单的办法就是全局安装它:
```bash
# Yarn
yarn global add react-devtools
Expand All @@ -58,13 +60,13 @@ yarn global add react-devtools
npm install -g react-devtools
```

Next open the developer tools from the terminal.
接下来从终端打开开发者工具:
```bash
react-devtools
```

It should connect to any local React Native app that's running.
它应该可以连接到任何正在运行的本地 React Native 应用程序。

> Try reloading the app if developer tools doesn't connect after a few seconds.
> 如果几秒钟后开发者工具未连接,请尝试重新加载应用程序。

[Learn more about debugging React Native.](https://reactnative.dev/docs/debugging)
[了解有关调试 React Native 的更多信息。](https://reactnative.dev/docs/debugging)