10个必要的地道面试问题 *

Toptal sourced essential questions that the best React Native developers and engineers can answer. 在我们社区的推动下,我们鼓励专家提交问题并提供反馈.

Hire a Top React Native Developer Now
Toptal logo是顶级自由软件开发人员的专属网络吗, designers, finance experts, product managers, and project managers in the world. 顶级公司雇佣Toptal自由职业者来完成他们最重要的项目.

Interview Questions

1.

What is the InteractionManager and how is it used? Why is it important?

View answer

The InteractionManager is the native module responsible for deferring the execution of a function until an “interaction” has finished. We can call InteractionManager.runAfterInteractions(() => {...}) to handle this deferral. We can also register our own interactions.

InteractionManager 是非常重要的,因为React Native有两个线程. 有一个JavaScript UI线程处理绘制更新到屏幕, 另一个线程用于所有不在UI线程上的任务. 因为只有一个线程进行UI更新, it can get overloaded and drop frames, 尤其是在导航屏幕动画中. We use the InteractionManager to ensure that our function is executed after 这些动画的出现使我们不会在UI线程上丢帧. Trying to draw a new screen while it is being animated is often too much for the thread to handle.

2.

这段查询本地API的代码有什么问题?

class GyroJs {
    setGyroPosition(pos) {
        If (pos === null || typeof pos === 'undefined') {
            抛出新的错误('必须定义位置');
        }
        this.pos = pos;
    }
    constructor() {
        const gyroscopePosition = NativeModules.MyGyroModule.gyroPosition();
        this.setGyroPosition(gyroscopePosition);
    }
}
View answer

的值总是抛出错误 gyroscopePosition will always be an unresolved Promise. 重要的是要记住,连接JavaScript和本机代码的桥梁是 asynchronous. We can either receive results from this side by passing in a callback (not done in this example), or by returning a Promise. In this case, we need to append a then() call to the gyroPosition() call and set the position inside it.

3.

Explain some of the fundamental tradeoffs between building with React Native and building a “true” native app.

View answer

React Native has exploded in popularity because the tradeoffs it provides make sense to many companies and teams. 但在React Native中构建应用并不总是正确的选择.

React Native makes sense when a team is building a product that does not need extremely high performance. 异步桥的局限性是3D游戏等游戏的瓶颈, and games with lots of particle updates. 依赖于与底层api进行深度交互的应用程序, or need large amounts of native code, might be easier to build as native apps.

React Native makes sense when an existing team is already proficient in JavaScript and/or has an existing React application built on the web or another platform. The “learn once, write everywhere” ethos advocated for by Facebook is very useful when diversifying a product across platforms. Hiring becomes easier, since JavaScript developers are plentiful, 你也不需要去找当地的专家.

React Native部分开源,部分闭源. Facebook maintains a private repository of React Native code that is used in their apps. When code from the private repo can be split off so that it contains nothing proprietary, 它经常被合并到开源代码库中. This leaves users of React Native with the classic tradeoff of open source software: There are often bugs—React Native is still in alpha form—and improvements can be spotty. On the other hand, motivated teams can make contributions to the source code and implement fixes and features that they need. Depending on a team’s resources and product roadmap, relying on open source may be the right choice.

申请加入Toptal的发展网络

and enjoy reliable, steady, remote Freelance React Native Developer Jobs

Apply as a Freelancer
4.

React Native和React之间的关系是什么?

View answer

React Native is built using React. React, at its core, is a library for “diffing” a virtual DOM and rendering this DOM to a screen with minimal operations. React, by default, does not have an opinion about which nodes are in its virtual DOM tree. 相反,它只是具有可以确定树中的变化并重新渲染的算法. web上的React提供了自己的节点原语(

, 等),它们是web应用程序的构建块. 但是可以定义新的节点原语,就像React Native所做的那样.

React Native defines its own primitives (, 等),它们不呈现HTML元素,而是映射到本地视图,比如 UIView and UIImageView. It implements a bridge that allows the JavaScript runtime to communicate asynchronously with the native runtime. React itself provides the tree diffing and rendering infrastructure that allows React Native to work.

5.

Are compile-to-JS libraries like TypeScript or ClojureScript compatible with React Native? Why or why not?

View answer

编译成JavaScript的语言通常与React Native兼容. React Native uses Babel to transform JavaScript into a form that is consumable by the native OS’s JavaScript runtime, using the react-native Babel plugin. As long as Babel can compile your JavaScript, and your code does not rely on web- or Node.它将在React Native中运行.

6.

Which node_modules will run in React Native? How can we test for this?

View answer

任何不依赖于Node的纯JavaScript库.Js运行时模块,并且不依赖于特定于web的概念(例如.g. window.location.pathname) will run fine in React Native. But we have to be mindful because there’s no way to test for this with Babel—it doesn’t scan these libraries for offending dependencies. A module that uses window.location.pathname 可能会在运行时意外的地方失败.

附加:对于显式依赖于Node的模块.js runtime modules, 我们可以经常使用Babel插件来浏览这些组件,以便在React Native中使用.

7.

React Native是如何为它的一些动画实现原生性能的?

View answer

Certain animation types, like Animation.timing and Animation.spring,可以在执行之前序列化并通过异步网桥发送. This allows the runtime to defer the actual drawing of the animation entirely to the native side, instead of trying to send positional values across the bridge as each frame is rendered. 这不适用于不能提前计算的动画. For example:

Animated.timing(new Animated.Value(0), {
  useNativeDriver: true,
  toValue: 100,
  duration: 100
}).start()

这将序列化操作,并在启动操作之前将其发送到本机.

8.

Why do we use StyleSheet.create? What are the tradeoffs with this approach?

View answer

StyleSheet is a module built into React Native that allows us to create immutable stylesheet references. 类中传递常规样式对象 create() 方法,模块将冻结对象,并为每个对象分配一个ID. This has two benefits: it allows us to avoid creating a new style object every render pass (which could lead to degradation of render performance), and it allows us to send the object across the asynchronous bridge only once (since these style objects map directly to native styles, they need to be passed across).

The key tradeoff with this method is that recomputing styles based on external criteria (like screen rotation or even a user-selected viewing mode) needs some infrastructure built to determine which styles to use. 如果对象是“原始”传递的,那么每次都可以动态地重新计算它们, based on arbitrary criteria.

9.

假设你有一个应用程序,它是一系列图像列表(例如.g. like Instagram). The app seems to crash at random. 在React Native中,我们可以采取哪些措施来调查和缓解这个问题呢?

View answer

Often, and especially on the Android platform, 滚动时不能正确地回收图像列表. 它们的内存永远不会被垃圾收集,也不会在较低的级别手动释放. This leads to out-of-memory (OOM) crashes that can occur seemingly at random as the app’s memory is exhausted.

We can investigate this by profiling the app’s heap memory usage in either Xcode or Android Studio. If you scroll through a list of images and notice the heap usage steadily climbing without ever dipping, 这可能意味着你的图像没有被正确地回收.

为了减轻这种情况,我们可以检查我们正在使用的列表实现. In modern versions of React Native, ListView should never be used; ensure that the FlatList 组件正在处理渲染. If this is not sufficient after tuning, you can try making your images lower resolution.

10.

Native apps that feel smooth often incorporate lots of little animations for state changes and transitions. How would you implement these behaviors?

View answer

React Native comes with the Animated API built in. 这个API是声明式的:我们使用 Animated.timing, Animated.spring, etc.,并提供动画运行所需的确切参数. This technique falls apart when we need lots of subtle and delicate animations on the fly; it’s not performant, 维护所有这些代码将是一场噩梦.

Instead, we look to the LayoutAnimation module, which is an interpolative API. We can invoke predefined LayoutAnimations, or define our own. LayoutAnimation 观察渲染循环周期之间元素位置的变化, 并计算元素在不同循环中的位置差. 然后,它插入这些变化并产生平滑的、本机驱动的动画.

面试不仅仅是棘手的技术问题, so these are intended merely as a guide. 并不是每一个值得雇佣的“A”候选人都能回答所有的问题, 回答所有问题也不能保证成为A级考生. At the end of the day, 招聘仍然是一门艺术,一门科学,需要大量的工作.

Why Toptal

Tired of interviewing candidates? 不知道该问什么才能让你得到一份好工作?

Let Toptal find the best people for you.

Hire a Top React Native Developer Now

我们独家的React原生开发者网络

希望找到一份React Native开发人员的工作?

Let Toptal find the right job for you.

Apply as a React Native Developer

Job Opportunities From Our Network

Submit an interview question

提交的问题和答案将被审查和编辑, 并可能会或可能不会选择张贴, at the sole discretion of Toptal, LLC.

* All fields are required

Looking for React Native Developers?

Looking for React Native Developers? 看看Toptal的React Native开发者.

Marcus Hsu

Freelance React Native Developer
United StatesToptal Member Since May 19, 2020

Marcus在前端开发方面有超过十年的经验, building React websites and developing iOS and Android apps in React Native for the past several years. He has helped at least 31 enterprises and startup clients to design and build high-quality cross-platform apps using React, React Native, and Node.js. Marcus has also built enterprise-scale apps that have impacted over 30 million users in 140 countries.

Show More

Donnie Waters

Freelance React Native Developer
United StatesToptal Member Since April 25, 2022

Donnie is a reliable front-end engineer passionate about learning new things while delivering efficient products. He has over six years of experience working as a software engineer focusing on React Native on the front end. 唐尼还兼职开发了自己的手机应用,下载量超过两百万.

Show More

Haleeq Usman

Freelance React Native Developer
United StatesToptal Member Since July 26, 2022

Haleeq is a leader in computer science with many years of experience in leading engineering teams for government institutions such as the Research Foundation of CUNY, top tech private companies, and corporations like Adobe. He is fluent in formal language theory, enabling him to effectively ship programs, apps, and services in any programming language. Haleeq拥有多年的企业应用架构和构建经验, services, and design patterns.

Show More

Toptal Connects the Top 3% of Freelance Talent All Over The World.

Join the Toptal community.

Learn more