You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何expo init生成的App.js使用export default function而非export default class?

Why expo init Creates Function Component App.js Instead of Class Component?

Great question! This shift is totally intentional on Expo's part, and it boils down to a couple of key reasons:

  • Expo Updated Its Default Project Templates
    Recent versions of the Expo CLI have replaced the old class-based App.js template with a function component version. This isn't a bug—it's a deliberate update to align with current development standards.

  • React's Modern Preferred Approach
    React has officially recommended function components paired with Hooks as the best way to write new React code for several years now. Hooks let you handle state, side effects, and other class component features with cleaner, more reusable code. Expo is just following this industry standard to give new projects a more up-to-date, maintainable starting point.

  • You Can Still Generate Class Component Templates
    If you need to stick with the class-based structure for your projects, you can explicitly specify the classic template when running expo init:

    expo init my_App_Name --template expo-template-blank-classic
    

    Alternatively, during the interactive setup flow, keep an eye out for template options labeled "classic" or "class component" (the exact wording might vary slightly based on your Expo CLI version).

内容的提问来源于stack exchange,提问作者Matt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:30:39