diff --git a/src/content/reference/react-dom/unmountComponentAtNode.md b/src/content/reference/react-dom/unmountComponentAtNode.md index 12f11dc74d..1881fef85e 100644 --- a/src/content/reference/react-dom/unmountComponentAtNode.md +++ b/src/content/reference/react-dom/unmountComponentAtNode.md @@ -4,15 +4,15 @@ title: unmountComponentAtNode -This API will be removed in a future major version of React. +此 API 将在未来的 React 主要版本中被移除。 -In React 18, `unmountComponentAtNode` was replaced by [`root.unmount()`](/reference/react-dom/client/createRoot#root-unmount). +在 React 18, `unmountComponentAtNode` 已被 [`root.unmount()`](/reference/react-dom/client/createRoot#root-unmount) 取代。 -`unmountComponentAtNode` removes a mounted React component from the DOM. +`unmountComponentAtNode` 用于从 DOM 中移除一个已挂载的 React 组件。 ```js unmountComponentAtNode(domNode) @@ -24,11 +24,11 @@ unmountComponentAtNode(domNode) --- -## Reference {/*reference*/} +## 参考 {/*reference*/} ### `unmountComponentAtNode(domNode)` {/*unmountcomponentatnode*/} -Call `unmountComponentAtNode` to remove a mounted React component from the DOM and clean up its event handlers and state. +使用 `unmountComponentAtNode` 从 DOM 中移除一个已挂载的 React 组件,并清除相关事件处理程序与状态。 ```js import { unmountComponentAtNode } from 'react-dom'; @@ -39,21 +39,21 @@ render(, domNode); unmountComponentAtNode(domNode); ``` -[See more examples below.](#usage) +[参见下面更多示例](#usage)。 -#### Parameters {/*parameters*/} +#### 参数 {/*parameters*/} -* `domNode`: A [DOM element.](https://developer.mozilla.org/en-US/docs/Web/API/Element) React will remove a mounted React component from this element. +* `domNode`:[DOM 节点](https://developer.mozilla.org/en-US/docs/Web/API/Element)。React 将从此节点移除已挂载的 React 组件。 -#### Returns {/*returns*/} +#### 返回值 {/*returns*/} -`unmountComponentAtNode` returns `true` if a component was unmounted and `false` otherwise. +如果 `unmountComponentAtNode` 成功移除对应的组件,将返回 `true`,否则返回 `false`。 --- -## Usage {/*usage*/} +## 用法 {/*usage*/} -Call `unmountComponentAtNode` to remove a mounted React component from a browser DOM node and clean up its event handlers and state. +使用 `unmountComponentAtNode` 从 浏览器 DOM 节点 中移除 已挂载的 React 组件,并清除有关事件处理程序与状态。 ```js [[1, 5, ""], [2, 5, "rootNode"], [2, 8, "rootNode"]] import { render, unmountComponentAtNode } from 'react-dom'; @@ -67,11 +67,11 @@ unmountComponentAtNode(rootNode); ``` -### Removing a React app from a DOM element {/*removing-a-react-app-from-a-dom-element*/} +### 从 DOM 节点移除 React 应用程序 {/*removing-a-react-app-from-a-dom-element*/} -Occasionally, you may want to "sprinkle" React on an existing page, or a page that is not fully written in React. In those cases, you may need to "stop" the React app, by removing all of the UI, state, and listeners from the DOM node it was rendered to. +有时你可能希望在一个已有的页面上添加一些 React 元素,或在一个没有完全使用 React 编写的页面上使用 React。在这些情况下,你可能需要从相关的 DOM 节点上移除所有 UI、状态和监听器,来“停止”React 应用程序。 -In this example, clicking "Render React App" will render a React app. Click "Unmount React App" to destroy it: +在这个例子中,点击“渲染 React 应用程序”将会渲染一个 React 应用程序;而点击“卸载 React 应用程序”将会销毁它: @@ -80,8 +80,8 @@ In this example, clicking "Render React App" will render a React app. Click "Unm My app - - + +
@@ -106,7 +106,7 @@ document.getElementById('unmount').addEventListener('click', () => { ```js App.js export default function App() { - return

Hello, world!

; + return

你好,世界!

; } ```