react從16升級到17版本後,npm run start 本地跑的時候散喚跡沒有問題,但是一旦build部署上去,就會白屏,然後出現這個報錯
點開一看,卡在沖並這里
查閱後得知,react從16升級到17後,相鏈埋應的react-dom也要升級到17,
輸入 npm i react-dom@17 --save 已解決
㈡ react native gradle怎麼升級
更新版本的React Native將會讓你訪問更多的APIs, 這樣我們可以去使用更多的APIs,視圖Views,以及開發者工具以及其他一些好用的東西。瀏覽版本更新日誌就會發現整體FB官方開發進度還是非常緊張的,這樣就很容易導致舊版本會出現不能用的情況,後期可能會出現不可預料的情況,這邊建議大家盡量更新最新正式版本。
我們大家都知道一個React Native項目使用Android項目,iOS項目和JavaScript項目三部分進行組成的,而且三者都關聯打包在npm包內的,所以該項目版本進行更新是比較繁瑣的。下面我來給大家講解一下React Native項目的升級步驟。
一、查看當前版本
[plain] view plain
<span style="font-family:SimSun;font-size:14px;">pengchengxiang@ubuntu:~/AwesomeProject$ react-native --version
react-native-cli: 0.2.0
react-native: 0.22.2</span>
二、查看最新的版本
[plain] view plain
<span style="font-family:SimSun;font-size:14px;">pengchengxiang@ubuntu:~/AwesomeProject$ npm info react-native
{ name: 'react-native',
'dist-tags': { latest: '0.25.1', next: '0.26.0-rc' },
versions:
[ '0.0.0',
'0.0.5',
... ...
'0.24.1',
'0.25.0-rc',
'0.25.1',
'0.26.0-rc' ],
maintainers:
... ...
dist:
{ shasum: '',
tarball: 'https://registry.npmjs.org/react-native/-/react-native-0.25.1.tgz' },
directories: {} }</span>
三、升級依賴的版本
[plain] view plain
<span style="font-family:SimSun;font-size:14px;">pengchengxiang@ubuntu:~/AwesomeProject$ npm install --save [email protected]
> [email protected] install /home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/bufferutil
> node-gyp rebuild
make: Entering directory `/home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/bufferutil/build'
CXX(target) Release/obj.target/bufferutil/src/bufferutil.o
SOLINK_MODULE(target) Release/obj.target/bufferutil.node
COPY Release/bufferutil.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/bufferutil/build'
> [email protected] install /home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/utf-8-validate
> node-gyp rebuild
make: Entering directory `/home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/utf-8-validate/build'
CXX(target) Release/obj.target/validation/src/validation.o
SOLINK_MODULE(target) Release/obj.target/validation.node
COPY Release/validation.node
make: Leaving directory `/home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/ws/node_moles/utf-8-validate/build'
> [email protected] postinstall /home/pengchengxiang/AwesomeProject/node_moles/react-native/node_moles/yeoman-generator/node_moles/cross-spawn/node_moles/spawn-sync
> node postinstall
npm WARN optional dep failed, continuing [email protected]
[email protected] node_moles/react-native
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── word[email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])</span>
㈢ react18出來了17還要學么
學。
react18是在react17的基礎上改進而來的,所以react17也要學好,不然如果放棄react17直接學react18,很多機理無法理解。
React18預計將會是一次談坦影響比較大的版本,不僅僅是因為它將會修改已有屬性,比如自動基喊批量處理、改進ssr的api支持等,還會正式帶來「並發渲染模式」以搏侍野及其周邊api如startTransition等。React18作為新的版本框架,如果後續你想要對自己的項目快速進行升級迭代,就需要提前掌握這個新版本。
㈣ React 18 發布、Vue 3、Vitest、Pinia 正式成為 Vue 官方推薦的狀態
Pinia 終於轉正了,它具有與 Vuex 5 幾乎完全相同或者增強的 API,簡單來說,它就是和 Vuex 5 名字不同。Vuex 3 和 4 仍會繼續維護,但是新功能不太可能會添加了。Pinia 也支持漸進式遷移,Vuex 和 Pinia 可以安裝在同一個項目中,新項目的話建議直接使用 Pinia。
Vite 發布了 v2.9.0。
React 18 終於發布了,官方團隊從 v16 就開始普及並發概念,到正式版發布時難免少了一些新鮮感。照目前的發展趨勢看,React 未來會朝著前端底層「操作系統」的方向發展,會變得越來越復陪笑陪雜。這些復雜的操作又會被元框架(Next.js、Remix)消化掉,開發者並不會直接接觸,使用這些元框架開發即可。
穩定不停滯,支持增量升級,v5、v6 的版本代碼可以同時存在。
下面是其他的發布信息和 TC39 提案的一些推進情況,大家可以找感興趣的自行查閱。
下面我們來看技術資料。
和好朋友卡頌一起在做的項目: 前端賞金獵人 。
這是一個用單純的金錢關系維系的前端學習社區,懸賞答題 + 答題賺錢。
期待你的加入,如果覺得有價值的話,可以給個 Star 鼓勵一下。
把技術名詞的大小寫拼蘆蠢寫正確是基本的素養,但很多人都不重視,這個項目可以幫助你糾正錯誤的大小寫。
免費的編程中文書籍索引,項目已有 90.1k Star。
從 2008 年穀歌瀏覽器推出至今的 100 個精彩瞬間回 憶錄。
在這里插入圖片描述
Pinia 是 Vue.js 的輕量級狀態管理庫,最近很受歡迎。它使用 Vue 3 中的新反應系統來構建一個直觀且完全類型化的狀態管理庫。
Pinia的成功可以歸功於其管理存儲數據的獨特功能(可擴展性、存儲模塊組織、狀態變化分組、多存儲創建等)。
另一方面,Vuex也是為Vue框架建立的一個流行的狀態管理庫,它也是Vue核心團隊推薦的狀態管理庫。 Vuex高度關注應用程序的可擴展性、開發人員的工效和信心。它基於與Rex相同的流量架構。
在這篇文章中,我們將對Pinia和Vuex進行比較。我們將分析這兩個框架的設置、社區優勢和性能。我們還將看一下Vuex 5與Pinea 2相比的新變化。
Pinia 設置
Pinia 很容易上手,因為它只需要安裝和創建一個store。
要安裝 Pinia,您可以在終端中運行以下命令:
該版本與Vue 3兼容,如果你正在尋找與Vue 2.x兼容的版本,請查看v1分支。
Pinia是一個圍繞Vue 3 Composition API的封裝器。因此,你不必把它作為一個插件來初始化,除非你需要Vue devtools支持、SSR支持和webpack代碼分割升斗的情況:
在上面的片段中,你將Pinia添加到Vue.js項目中,這樣你就可以在你的代碼中使用Pinia的全局對象。
為了創建一個store,你用一個包含創建一個基本store所需的states、actions和getters的對象來調用 defineStore 方法。
Vuex 也很容易設置,需要安裝和創建store。
要安裝Vuex,您可以在終端中執行以下命令:
要創建store,你可以使用包含創建基本store所需的states、actions和 getter 的對象調用 createStore 方法:
要訪問 Vuex 全局對象,需要在 Vue.js 項目根文件中添加 Vuex,如下所示:
使用 Pinia,可以按如下方式訪問該store:
請注意,在訪問其屬性時省略了 store 的 state 對象。
使用Vuex,可以按如下方式訪問store:
這兩個狀態管理庫都相當容易學習,因為它們在 YouTube 和第三方博客上都有很好的文檔和學習資源。對於以前有使用 Rex、MobX、Recoil 等 Flux 架構庫經驗的開發人員來說,他們的學習曲線更容易。
這兩個庫的文檔都很棒,並且以對經驗豐富的開發人員和新開發人員都友好的方式編寫。
Pinia和Vuex都非常快,在某些情況下,使用Pinia的web應用程序會比使用Vuex更快。這種性能的提升可以歸因於Pinia的極輕的重量,Pinia體積約1KB。
盡管Pinia是在Vue devtools的支持下建立的,但由於Vue devtools沒有暴露出必要的API,所以一些功能如時間旅行和編輯仍然不被支持。當開發速度和調試對你的項目來說更重要時,這是值得注意的。
Pinia 將這些與 Vuex 3 和 4 進行了比較:
這些是Pinia在其狀態管理庫和Vuex之間的比較中提出的額外見解:
將 Pinia 2(目前處於 alpha 階段)與 Vuex 進行比較,我們可以推斷出 Pinia 領先於 Vuex 4。
Vue.js核心團隊為Vuex 5制定了一個開放的RFC,類似於Pinia使用的RFC。目前,Vuex通過RFC來盡可能多地收集社區的反饋。希望Vuex 5的穩定版本能夠超越Pinea 2。
據同時也是 Vue.js 核心團隊成員並積極參與 Vuex 設計的 Pinia 的創建者(Eardo San Martin Morote)所說,Pania 和 Vuex 的相似之處多於不同之處:
盡管 Pinia 足以取代 Vuex,但取代 Vuex 並不是它的目標,因此 Vuex 仍然是 Vue.js 應用程序的推薦狀態管理庫。
根據我的個人經驗,由於Pinea是輕量級的,體積很小,它適合於中小型應用。它也適用於低復雜度的Vue.js項目,因為一些調試功能,如時間旅行和編輯仍然不被支持。
將 Vuex 用於中小型 Vue.js 項目是過度的,因為它重量級的,對性能降低有很大影響。因此,Vuex 適用於大規模、高復雜度的 Vue.js 項目。
批處理是 React將多個狀態更新分組到單個重新渲染中以獲得更好的性能。
例如,如果你在同一個點擊事件中有兩個狀態更新,React 總是將它們分批處理到一個重新渲染中。如果你運行下面的代碼,你會看到每次點擊時,React 只執行一次渲染,盡管你設置了兩次狀態:
這對性能非常有用,因為它避免了不必要的重新渲染。它還可以防止你的組件呈現僅更新一個狀態變數的「半完成」狀態,這可能會導致錯誤。
這可能會讓你想起餐廳服務員在你選擇第一道菜時不會跑到廚房,而是等你完成訂單。
然而,React 的批量更新時間並不一致。例如,如果你需要獲取數據,然後更新handleClick上面的狀態,那麼 React不會批量更新,而是執行兩次獨立的更新。
這是因為 React 過去只在瀏覽器事件(如點擊)期間批量更新,但這里我們在事件已經被處理(在 fetch 回調中)之後更新狀態:
在 React 18 之前,我們只在 React 事件處理程序期間批量更新。默認情況下,React 中不會對 promise、setTimeout、本機事件處理程序或任何其他事件中的更新進行批處理。
從 React 18 開始createRoot,所有更新都將自動批處理,無論它們來自何處。
這意味著超時、承諾、本機事件處理程序或任何其他事件內的更新將以與 React 事件內的更新相同的方式進行批處理。
我們希望這會導致更少的渲染工作,從而在你的應用程序中獲得更好的性能:
注意:作為採用 React 18 的一部分,預計你將升級到createRoot。舊行為的render存在只是為了更容易地對兩個版本進行生產實驗。
無論更新發生在何處,React 都會自動批量更新,因此:
行為與此相同:
通常,批處理是安全的,但某些代碼可能依賴於在狀態更改後立即從 DOM 中讀取某些內容。對於這些用例,你可以使用ReactDOM.flushSync()選擇退出批處理:
2、Suspense 的 SSR 支持
這基本上是伺服器端渲染 (SSR) 邏輯的擴展。在典型的 React SSR 應用程序中,會發生以下步驟:
典型 SSR 應用程序的問題在於,在下一步可以開始之前,必須立即完成整個應用程序的每個步驟。這會使您的應用程序在初始載入時變慢且無響應。
React 18 正試圖解決這個問題。 組件已經以這樣的方式進行了革命性的改變,它將應用程序分解為更小的獨立單元,這些單元經過提到的每個步驟。這樣一旦用戶看到內容,它就會變成互動的。
我們將狀態更新分為兩類:
單擊、懸停、滾動或打字等緊急更新需要立即響應以匹配我們對物理對象行為方式的直覺。否則他們會覺得「錯了」。
然而,轉換是不同的,因為用戶不希望在屏幕上看到每個中間值。
例如,當您在下拉列表中選擇過濾器時,您希望過濾器按鈕本身在您單擊時立即響應。但是,實際結果可能會單獨轉換。
一個小的延遲是難以察覺的,而且通常是預料之中的。如果在結果渲染完成之前再次更改過濾器,您只關心看到最新的結果。
在典型的 React 應用程序中,大多數更新在概念上都是過渡更新。但出於向後兼容性的原因,過渡是可選的。
默認情況下,React 18 仍然將更新處理為緊急更新,您可以通過將更新包裝到startTransition.
構建流暢且響應迅速的應用程序並不總是那麼容易。有時,諸如單擊按鈕或輸入輸入之類的小動作可能會導致屏幕上發生很多事情。這可能會導致頁面在所有工作完成時凍結或掛起。
例如,考慮在過濾數據列表的輸入欄位中鍵入。您需要將欄位的值存儲在 state 中,以便您可以過濾數據並控制該輸入欄位的值。您的代碼可能如下所示:
在這里,每當用戶鍵入一個字元時,我們都會更新輸入值並使用新值來搜索列表並顯示結果。
對於大屏幕更新,這可能會導致頁面在呈現所有內容時出現延遲,從而使打字或其他交互感覺緩慢且無響應。
即使列表不是太長,列表項本身也可能很復雜並且每次擊鍵時都不同,並且可能沒有明確的方法來優化它們的呈現。
從概念上講,問題在於需要進行兩種不同的更新。第一個更新是緊急更新,用於更改輸入欄位的值,以及可能會更改其周圍的一些 UI。
第二個是顯示搜索結果的不太緊急的更新。
用戶希望第一次更新是即時的,因為這些交互的本機瀏覽器處理速度很快。但是第二次更新可能會有點延遲。
用戶不希望它立即完成,這很好,因為可能有很多工作要做。(實際上,開發人員經常使用去抖動等技術人為地延遲此類更新。)
在 React 18 之前,所有更新都被緊急渲染。
這意味著上面的兩個狀態仍然會同時呈現,並且仍然會阻止用戶看到他們交互的反饋,直到一切都呈現出來。我們缺少的是一種告訴 React 哪些更新是緊急的,哪些不是的方法。
新startTransitionAPI 通過讓您能夠將更新標記為「轉換」來解決此問題:
包裝在其中的更新startTransition被視為非緊急處理,如果出現更緊急的更新(如點擊或按鍵),則會中斷。
如果用戶中斷轉換(例如,連續輸入多個字元),React 將拋出未完成的陳舊渲染工作,僅渲染最新更新。
Transitions 可讓您保持大多數交互敏捷,即使它們導致顯著的 UI 更改。它們還可以讓您避免浪費時間渲染不再相關的內容。
上述問題的一個常見解決方案是將第二次更新包裝在 setTimeout 中:
這將延遲第二次更新,直到呈現第一次更新之後。節流和去抖動是這種技術的常見變體。
一個重要的區別是startTransition不安排在以後喜歡的setTimeout是。它立即執行。傳遞給的函數startTransition同步運行,但其中的任何更新都標記為「轉換」。
React 將在稍後處理更新時使用此信息來決定如何呈現更新。這意味著我們比在超時中包裝更新更早地開始呈現更新。
在快速設備上,兩次更新之間的延遲非常小。在較慢的設備上,延遲會更大,但 UI 會保持響應。
另一個重要的區別是 a 內的大屏幕更新setTimeout仍然會鎖定頁面,只是在超時之後。
如果用戶在超時觸發時仍在鍵入或與頁面交互,他們仍將被阻止與頁面交互。但是標記為 的狀態更新startTransition是可中斷的,因此它們不會鎖定頁面。
它們讓瀏覽器在呈現不同組件之間的小間隙中處理事件。
如果用戶輸入發生變化,React 將不必繼續渲染用戶不再感興趣的內容。
最後,因為setTimeout只是延遲更新,顯示載入指示器需要編寫非同步代碼,這通常很脆弱。
通過轉換,React 可以為您跟蹤掛起狀態,根據轉換的當前狀態更新它,並讓您能夠在用戶等待時顯示載入反饋。
您可以使用startTransition來包裝要移動到後台的任何更新。通常,這些類型的更新分為兩類:
總結
React 18 沒有任何重大更改,因此,我們將當前的存儲庫升級到最新版本幾乎不需要更改代碼,但我們可以享受它們很酷的功能。
㈤ React Fiber
隨著 React 16 的發布,Hooks 的正式上線,很多小夥伴都很興奮,都想要嘗試這一新的特性,升級 React 的意願越來越強烈了。
我們都知道 React 是一個優秀的前端框架,很多的大型應用都在使用,而作為使用 React 為工具的開發者也應謹明該了解下 React Fiber,Fiber 到底是什麼?它能給我們帶來什麼?以及 React 團隊為什麼要去重寫 Fiber 架構?
React Fiber 是 React 16 中新的協調引擎,是對核心演算法的一次重新實現。
在 React 16 以前,當元素較多,需要頻繁刷新的時候頁面會出現卡頓,究其原因是因為更新過程是同步的,大量的同步計算任務阻塞了碧桐瀏覽器的渲染。
當頁面載入或者更新時,React 會去計算和比對 Virtual DOM,最後繪制頁面,整個過程是同步進行的。當 JavaScript 在瀏覽器的主線程上長期運行,就會阻塞了樣式計算、布局和繪制,導致頁面無法得到及時的更新和響應。此時,無論用戶如何點擊滑鼠或者敲擊鍵盤都不會得到響應,當 React 更新完成後剛剛點擊或敲擊的事件才會得到響應。
由於 JavaScript 是單線程的特點,所以一個線程執行完成後才會執行下一個線程,當上一個線程任務耗時太長,程序就會對其他輸入不作出響應。
React 的更新過程會先計算,一旦任務開始進行,就無法中斷, js 將一直祥慧告佔用主線程, 直到整棵 Virtual DOM 樹計算完成之後,才能把執行權交給渲染引擎,而 React Fiber 就是要改變現狀。
接下來,讓我們具體來了解下 Fiber。
Fiber 把耗時長的任務拆分成很多的小片,每個小片的運行時間很短,每次只執行一個小片,執行完後看是否還有剩餘時間,如果有就繼續執行下個小片,如果沒有就掛起當前任務,將控制權交給 React 負責任務協調的模塊,看有沒有其他緊急任務要做,如果沒有就繼續更新當前任務,如果有緊急任務就去做緊急任務,等主線程不忙的時候在繼續執行當前任務。
這樣唯一的線程不會被獨占,其他任務依然有運行的機會。
這種策略叫做 Cooperative Scheling(合作式調度),操作系統常用任務調度策略之一。
總而言之,我們了解到,Fiber 是一個最小工作單元,也是堆棧的重新實現,可以理解為是一個虛擬的堆棧幀。它將可中斷的任務拆分成多個任務,通過優先順序來自由調度子任務,分段更新,從而將之前的同步渲染改為非同步渲染。
維護每一個分片的數據結構,就是 Fiber,它可以用 JS 對象來表示,其中包含有關組件,以及輸入和輸出的信息:
上面講到了任務的執行是根據優先順序來調度的,那我們現在具體了解一下優先順序。
Fiber Reconciler 決定了當任務調度完成之後,如何去執行每個任務,如何去更新每一個節點的過程。
React Fiber 更新過程分為兩個階段
首次渲染之後 React 會得到一個 Fiber 樹,也就是 Current tree(當前樹)。當處理更新的時候,React 會構建 WorkInProgress Tree(工作過程樹),當構造完成後會將 current 指針指向 WorkInProgress Tree,WorkInProgress Tree 成了新的 Fiber tree。
這被稱做雙緩沖。以 Fiber tree 為主,WorkInProgress Tree 為輔。
雙緩沖技術可以復用內部對象(fiber),節省內存分配、GC的時間開銷。
本篇文章篇幅有限,大致講了 Fiber 的相關知識和 React 的工作流程,對於細節,比如:如何調度任務,如何 diff 等,感興趣的同學可以自行結合源碼研究分析。
㈥ RN錯誤總結
1.invariant violation:expected a component class,got[object object]
創建自定義組件首字母要大寫,否則會報錯.
2.Mole 0 is not a registered callable mole.
將gradle升級成最新版本( cd Android 進入android目錄執行: sudo ./gradlew clean )
或者通過android studio工具升級.
3.android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
該錯誤屬於安卓Native的錯誤,如果引用的Activity不存在或者已經銷毀,再次引用就會報該錯誤,如果是react native 調用原生控制項的話,創建控制項需要引用:getCurrentActivity()
4.android.app.Application cannot be cast to com.facebook.react.ReactApplication
需要將創建的MainApplication在AndroidManifest.xml配迅者置好.
5.Element type is invalid: expected a string (for built-in components) or a class/function but got: object
發生原生一般是你引用了無效的組件,如果組件確實正確,看下引用的組件是否正常導出:(export defalut)
6.react native undefined is not an object (evaluating this....
發生該錯誤的一般是忘記bind(this),只要回調函數中需要用到this的,一般都需要bind.
7.react native - expected a component class, got [object Object]
該錯誤可能是你引用了小寫的組件,組件首字母一定要大寫,比如<image>應該寫成<Image>
8.通過網路獲取的圖片,設置其resizeMode一定要設置高度和寬度
9,CMD+R刷新無效
release模式下,調試無效畝啟薯,在路徑、變數名旁廳、文件名等地方不要使用中文,例如圖片名,設置為中文的話調試時候是不顯示的
或者是沒有設置鍵盤輸入:
㈦ ReactNative(二)RN拆包,patch補丁,diff差異文件升級方案
這里對第敏凱談三種 Patch補丁方案進行深入的探討和記錄
warning:以下拆包針對rn打出孫物的bundle包,和上一次討論的npm拆模塊不一樣橋碰。
㈧ react-native-tab-view的兩個問題記錄
最近在使用 react-native-tab-view 時發現了兩個問題。
1.安卓上手勢沖突
問題描核虛述:如上圖,紅框banner區域的滑動會和整個頁面(作為Tab中的一項)的滑動沖突,在安卓上表現出的現象就是大概率滑動banner觸發的都是頁面的滑動。
預期:滑動banner不觸發頁面的滑動,非banner區域觸發。
問題原因:組件內部的Pager控制手勢用的是 react-native-gesture-handler 中的PanGestureHandler,banner用的是 @react-native-community/viewpager ,猜測就是這兩個庫的手勢沖突了
解決方案:因為 RN 沒法處理手勢優先順序,思路就是如果兩者底層都是用一個Pager是不是就沒這個問題。於是將 react-native-tab-view 的Pager替換成 @react-native-community/viewpager ,果然問題就解決了。
PS: 這里要注意 react-native-tab-view 在2.10版本以上支持自定義Pager,可以用官方readme中推薦的 react-native-tab-view-viewpager-adapter ;如果是小於2.10版本,又不好升級(因為2.10開始要升 react-native-reanimated ,而它又牽涉到Android X,需要 RN 60+的支持),這個時候就只能改源碼了。
PPS:由於替換成了viewPager,還解決了一級頁面需要套一層 gestureHandlerRootHOC 的問題,gestureHandlerRootHOC 導致的crash問題也就自然解決了。
2.低端機上 Tab 定位慢的問題
問題描述:如上圖,左右分別是before和after,在前氏豎低端機上我們發現tab切過去後,tab欄的定位以及內容的展示要好幾秒才完成。
預期:滑動後立即響應
問題原因:這個問題通過對源碼的調試發現,居然是tabitem上切換時文字動畫拖累的,所有其它的動畫都要等這個動畫完成才執行,具體為什麼這個動畫如此慢,還需要繼續研究。大概就是下面這樣一段動畫處理:
解決方案:我們在低端機或者全平台去掉這個動畫即可
最後,如果大家覺得 react-native-tab-view 真的很坑,向大家推薦我司同學自己封裝的一個tab庫慧大: https://github.com/smadey/react-native-tabify ,上述問題都不存在。
㈨ react提示校驗失敗
react提示校腔虧驗失敗的解決方法有:
1、升級到最新版。
2、徹底卸伍核神載原來的版本再氏告重新安裝。
3、可能是系統問題。
㈩ Taro 從1.2.26升級到3.4.8,遇到的坑
先全局升級taro到最新版本3.4.8
【1】然後本地init一個項目包,myapp
【2】把之前1.2.26的項目中的src文件夾,替換到myapp中
【3】在myapp中,安裝 [email protected] 版本
【4】刪掉全局中,所有的 ,import '@tarojs/async-await'
【5】之前引入taro,component的方式,全局都要替換
import Taro, { Component } from '@tarojs/taro'
替換陸哪為以下:
import Taro from '@tarojs/taro'
import React, { Component } from "react";
【6】 安裝rex
npm install rex react-rex rex-thunk rex-logger
把app.ts 中, Provider的引入,換成react-rex
import { Provider } from 'react-rex'
全局pages和自定義組件中,connect的引入,換成react-rex
import { connect } from 'react-rex';
【7】引入自定義組件的方式,去掉{}
import { XxxxxXxxx } from '../../component/xxxxxx' 替換為
import XxxxxXxxx from '../../component/xxxxxx'
【8】所有文件中,config的部分,都摘出去,放在同一目錄下的config.js文件中
改為後的app.tsx是這樣早散碼的
import React, { Component } from 'react'
import { Provider } from 'react-rex'
import configStore from './store'
import './app.scss'
const store = configStore();
class App extends Component {
render() {
<Provider store={store} >
{this.props.children}
</Provider>
}
}
export default App
然後運行試試。
ps:我這邊運行的時候不報錯了,但是微信開發者工具,顯示有問題。
參考鏈接:掘扮http://t.zoukankan.com/Nyan-Workflow-FC-p-13529088.html