Skip to content

Commit

Permalink
Update src/content/reference/react/useReducer.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Yucohny authored Jul 12, 2023
1 parent 0da991a commit 112e126
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/content/reference/react/useReducer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ return <button onClick={(e) => handleClick(e)}>Click me</button>

### 我的 reducer 和初始化函数运行了两次 {/*my-reducer-or-initializer-function-runs-twice*/}

[严格模式](/reference/react/StrictMode) 下 React 会调用两次 reducer 和初始化函数,这不应该会破坏你的代码逻辑
[严格模式](/reference/react/StrictMode) 下 React 会调用两次 reducer 和初始化函数,但是这不应该会破坏你的代码逻辑

这个 **仅限于开发模式** 的行为可以帮助你 [保持组件纯粹](/learn/keeping-components-pure):React 会使用其中一次调用结果并忽略另一个结果。如果你的组件、初始化函数以及 reducer 函数都是纯函数,这并不会影响你的逻辑。不过一旦它们存在副作用,这个额外的行为就可以帮助你发现它。

Expand Down

0 comments on commit 112e126

Please sign in to comment.