![](/img/trans.png)
[英]What exactly <React.StrictMode></React.StrictMode> component does?
[英]Adding React-Redux to a React app with React.StrictMode tag
最新的 create-react-app 默認情況下在組件周圍有<React.StrictMode>
標簽。 我看到的每個將 react-redux 添加到應用程序的示例都沒有 React.StrictMode 標記。
這是我所做的:
<Provider store={store}>
<React.StrictMode>
<App />
</React.StrictMode>
</Provider>,
document.getElementById('root')
但是,我總是看到:
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
我閱讀了StrictMode的用途。 我認為它有助於調試和洞察應用程序中的問題,所以我想在開發時保留它。 我所做的是正確的還是應該像所有示例中一樣完全替換它?
React.StrictMode
也應該包裝整個應用程序,包括提供程序。 所以改變你的代碼如下:
從
<Provider store={store}>
<React.StrictMode>
<App />
</React.StrictMode>
</Provider>,
document.getElementById('root')
至
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
document.getElementById('root')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.