RN 各种小问题
问题:vs code 无法启动 双击无反应
方法:控制台 输入 netsh winsock reset
重启 vs
问题:RN Debugger Network 不显示
See the comments of node_modules/
react-native/Libraries/Core/InitializeCore.js#L43-L53
. It uses XMLHttpRequest
from WebWorker in Chrome, basically it can manually setup by:
global.XMLHttpRequest = global.originalXMLHttpRequest
? global.originalXMLHttpRequest
: global.XMLHttpRequest
global.FormData = global.originalFormData
? global.originalFormData
: global.FormData
fetch // Ensure to get the lazy property
if (window.__FETCH_SUPPORT__) {
// it's RNDebugger only to have
window.__FETCH_SUPPORT__.blob = false
} else {
/*
* Set __FETCH_SUPPORT__ to false is just work for `fetch`.
* If you're using another way you can just use the native Blob and remove the `else` statement
*/
global.Blob = global.originalBlob ? global.originalBlob : global.Blob
global.FileReader = global.originalFileReader
? global.originalFileReader
: global.FileReader
}
RN 警告:
Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
方法来自: https://blog.csdn.net/softwarenb/article/details/81123389
方法 1:组件被销毁之前重写setState方法 不对状态做任何改变
componentWillUnmount() {
this.setState = (state, callback) => {
return;
};
}
方法 2:组件被销毁之前可以 setState 销毁之后就不能 setState (待测)
componentWillMount() {
this._isMounted = true
fetch('网络请求').then(status, response) => {
if (this._isMounted) {
this.setState({
activityTipsImg: response.data.tips_url,
activityTipsContent: response.data.tips_content
})
}
});
}
componentWillUnmount() {
this._isMounted = false
}