What’s the advantage of using Promises over callbacks in native modules?
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: "Promises enable async/await syntax". Phương thức native có thể trả kết quả về JavaScript bằng callback hoặc Promise; với Promise, phía native nhận cặp resolve và reject (RCTPromiseResolveBlock trên iOS, tham số Promise trên Android), còn phía JavaScript có thể viết await MyModule.doWork() trong hàm async, bắt lỗi bằng try/catch và tránh lồng callback nhiều tầng. "Promises are faster" sai vì cả hai đều đi qua cùng cơ chế gọi native bất đồng bộ; Promise không làm lời gọi nhanh hơn. "Promises are synchronous" sai vì Promise biểu diễn kết quả bất đồng bộ, giá trị chỉ có sau khi phía native gọi resolve. "Promises support JSON only" sai vì Promise không giới hạn kiểu; giá trị trả về chỉ cần là kiểu mà bridge chuyển được như chuỗi, số, mảng, đối tượng.
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