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

最好的React Native开发人员和工程师可以回答的全部基本问题. 在我们社区的推动下,我们鼓励专家提交问题并提供反馈.

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 本机模块是否负责延迟函数的执行,直到“交互”完成. 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线程上丢帧. 尝试在动画中绘制一个新屏幕通常是线程无法处理的.

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. 我们可以通过传递回调来从这边接收结果(在本例中没有这样做), 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.

解释使用React Native和构建“真正的”原生应用之间的一些基本权衡.

View answer

React Native之所以大受欢迎,是因为它为许多公司和团队提供了合理的权衡. 但在React Native中构建应用并不总是正确的选择.

当一个团队正在构建一个不需要极高性能的产品时,React Native是有意义的. 异步桥的局限性是3D游戏等游戏的瓶颈, and games with lots of particle updates. 依赖于与底层api进行深度交互的应用程序, or need large amounts of native code, might be easier to build as native apps.

当一个现有的团队已经精通JavaScript和/或有一个现有的React应用程序构建在web或其他平台上时,React Native是有意义的. The “learn once, Facebook所倡导的“到处写”的理念在实现产品跨平台多样化时非常有用. Hiring becomes easier, since JavaScript developers are plentiful, 你也不需要去找当地的专家.

React Native部分开源,部分闭源. Facebook维护着一个私有的React Native代码库,用于他们的应用程序. 当私有代码库中的代码可以被分离出来而不包含任何专有代码时, 它经常被合并到开源代码库中. 这就给React Native的用户留下了开源软件的经典权衡:经常会有bug (React Native仍然处于alpha版本),而且改进可能是参差不齐的. On the other hand, 受到激励的团队可以对源代码做出贡献,并实现他们需要的修复和特性. 根据团队的资源和产品路线图,依赖开源可能是正确的选择.

申请加入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, 是否有一个库用于“区分”虚拟DOM并以最少的操作将该DOM呈现到屏幕上. 默认情况下,React不知道它的虚拟DOM树中有哪些节点. 相反,它只是具有可以确定树中的变化并重新渲染的算法. web上的React提供了自己的节点原语(

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

React Native defines its own primitives (, 等),它们不呈现HTML元素,而是映射到本地视图,比如 UIView and UIImageView. 它实现了一个桥接,允许JavaScript运行时与本机运行时进行异步通信. React本身提供了允许React Native工作的树区分和渲染基础设施.

5.

像TypeScript或ClojureScript这样的编译到js的库是否与React Native兼容? Why or why not?

View answer

编译成JavaScript的语言通常与React Native兼容. React Native使用Babel将JavaScript转换为可被本地操作系统的JavaScript运行时使用的形式, using the react-native Babel plugin. 只要Babel可以编译你的JavaScript,并且你的代码不依赖于web-或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. 但是我们必须注意,因为没有办法用babel来测试这一点——它不会扫描这些库是否有冒犯性的依赖. 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,可以在执行之前序列化并通过异步网桥发送. 这允许运行时将动画的实际绘制完全推迟到本机端, 而不是试图发送位置值在桥上的每一帧渲染. 这不适用于不能提前计算的动画. 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 是一个模块内置到React Native,允许我们创建不可变的样式表引用. 类中传递常规样式对象 create() 方法,模块将冻结对象,并为每个对象分配一个ID. 这有两个好处:它允许我们避免在每次渲染过程中创建一个新的样式对象(这可能导致渲染性能下降)。, 它允许我们通过异步桥只发送一次对象(因为这些样式对象直接映射到本地样式), they need to be passed across).

这种方法的关键缺点是,基于外部标准(如屏幕旋转或甚至用户选择的观看模式)重新计算样式需要构建一些基础设施来确定使用哪种样式. 如果对象是“原始”传递的,那么每次都可以动态地重新计算它们, 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, 滚动时不能正确地回收图像列表. 它们的内存永远不会被垃圾收集,也不会在较低的级别手动释放. 这将导致内存不足(OOM)崩溃,当应用程序的内存耗尽时,这种崩溃可能会随机发生.

我们可以通过在Xcode或Android Studio中分析应用程序的堆内存使用情况来研究这个问题. 如果您滚动图像列表并注意到堆使用情况稳步攀升而没有下降, 这可能意味着你的图像没有被正确地回收.

为了减轻这种情况,我们可以检查我们正在使用的列表实现. In modern versions of React Native, ListView should never be used; ensure that the FlatList 组件正在处理渲染. 如果调优后这还不够,您可以尝试降低图像的分辨率.

10.

感觉流畅的原生应用通常包含许多用于状态变化和过渡的小动画. 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? Not sure what to ask to get you a top hire?

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在前端开发方面有超过十年的经验, 在过去的几年里,我一直在用React Native构建React网站,开发iOS和Android应用. 他已经帮助至少31家企业和初创客户使用React设计和构建了高质量的跨平台应用程序, React Native, and Node.js. Marcus还开发了企业级应用,影响了140个国家的3000多万用户.

Show More

Donnie Waters

Freelance React Native Developer

United StatesToptal Member Since April 25, 2022

Donnie是一位值得信赖的前端工程师,他热衷于学习新事物,同时提供高效的产品. 他有超过六年的软件工程师工作经验,专注于前端的React Native. 唐尼还兼职开发了自己的手机应用,下载量超过两百万.

Show More

Haleeq Usman

Freelance React Native Developer

United StatesToptal Member Since July 26, 2022

Haleeq是计算机科学领域的领导者,在领导政府机构(如纽约市立大学研究基金会)的工程团队方面拥有多年的经验, 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