Why should native modules not execute heavy tasks on the UI thread?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "Can freeze UI or cause lag". UI thread (luồng giao diện, còn gọi là main thread) vừa vẽ khung hình vừa xử lý chạm; nếu native module chạy việc nặng như đọc tệp lớn, xử lý ảnh hay gọi mạng đồng bộ trên luồng này thì không còn thời gian vẽ khung hình kế tiếp, ứng dụng giật, đứng hình, trên Android có thể hiện ANR. Vì vậy việc nặng nên chạy ở luồng nền rồi trả kết quả qua Promise hoặc callback. "Causes Redux conflict" sai vì Redux là thư viện trạng thái phía JavaScript, không phụ thuộc luồng native. "Makes hooks invalid" sai vì luật của hook chỉ liên quan thứ tự gọi trong component, không dính tới native thread. "Prevents JSX compilation" sai vì JSX được Babel biên dịch lúc build, trước khi ứng dụng chạy.
Cùng chương 1
Ordering steps in the process of how React Native works in Bridge architecture:
1.The main cable starts working and starts loading JavaScript loads
2.Produces a new DOM (structure) and sends changes to Shadow cable
3.If the JavaScript code is successfully uploaded, the main thread sends it to another JavaScript thread
4.Main thread is able to render something on the screen
5.The shadow string calculates the structure and sends the parameters/properties of the structure to the main sequenceCó lời giảiCâu hỏiReact Native uses the following tech stack to build cross-platform native apps:Có lời giảiCâu hỏiHow does React Native differ from React.js in terms of rendering components?Có lời giảiCâu hỏiCả 54 câu của chủ đề54 câu