|
| 1 | +--- |
| 2 | +id: getting-started-without-a-framework |
| 3 | +title: Get Started Without a Framework |
| 4 | +hide_table_of_contents: true |
| 5 | +--- |
| 6 | + |
| 7 | +import Tabs from '@theme/Tabs'; |
| 8 | +import TabItem from '@theme/TabItem'; |
| 9 | +import constants from '@site/core/TabsConstants'; |
| 10 | +import PlatformSupport from '@site/src/theme/PlatformSupport'; |
| 11 | + |
| 12 | +import RemoveGlobalCLI from './\_remove-global-cli.md'; |
| 13 | + |
| 14 | +<PlatformSupport platforms={['android', 'ios', 'macOS', 'tv', 'watchOS', 'web', 'windows', 'visionOS']} /> |
| 15 | + |
| 16 | +If you have constraints that are not served well by a [Framework](/architecture/glossary#react-native-framework), or you prefer to write your own Framework, you can create a React Native app without using a Framework. |
| 17 | + |
| 18 | +To do so, you'll first need to [set up your environment](set-up-your-environment). Once you're set up, continue with the steps below to create an application and start developing. |
| 19 | + |
| 20 | +### Step 1: Creating a new application |
| 21 | + |
| 22 | +<RemoveGlobalCLI /> |
| 23 | + |
| 24 | +You can use [React Native Community CLI](https://github.com/react-native-community/cli) to generate a new project. Let's create a new React Native project called "AwesomeProject": |
| 25 | + |
| 26 | +```shell |
| 27 | +npx @react-native-community/cli@latest init AwesomeProject |
| 28 | +``` |
| 29 | + |
| 30 | +This is not necessary if you are integrating React Native into an existing application, or if you've installed [Expo](https://docs.expo.dev/bare/installing-expo-modules/) in your project, or if you're adding Android support to an existing React Native project (see [Integration with Existing Apps](integration-with-existing-apps.md)). You can also use a third-party CLI to set up your React Native app, such as [Ignite CLI](https://github.com/infinitered/ignite). |
| 31 | + |
| 32 | +:::info |
| 33 | + |
| 34 | +If you are having trouble with iOS, try to reinstall the dependencies by running: |
| 35 | + |
| 36 | +1. `cd ios` to navigate to the `ios` folder. |
| 37 | +2. `bundle install` to install [Bundler](https://bundler.io/) |
| 38 | +3. `bundle exec pod install` to install the iOS dependencies managed by CocoaPods. |
| 39 | + |
| 40 | +::: |
| 41 | + |
| 42 | +#### [Optional] Using a specific version or template |
| 43 | + |
| 44 | +If you want to start a new project with a specific React Native version, you can use the `--version` argument: |
| 45 | + |
| 46 | +```shell |
| 47 | +npx @react-native-community/ [email protected] init AwesomeProject --version X.XX.X |
| 48 | +``` |
| 49 | + |
| 50 | +You can also start a project with a custom React Native template with the `--template` argument, read more [here](https://github.com/react-native-community/cli/blob/main/docs/init.md#initializing-project-with-custom-template). |
| 51 | + |
| 52 | +### Step 2: Start Metro |
| 53 | + |
| 54 | +[**Metro**](https://metrobundler.dev/) is the JavaScript build tool for React Native. To start the Metro development server, run the following from your project folder: |
| 55 | + |
| 56 | +<Tabs groupId="package-manager" queryString defaultValue={constants.defaultPackageManager} values={constants.packageManagers}> |
| 57 | +<TabItem value="npm"> |
| 58 | + |
| 59 | +```shell |
| 60 | +npm start |
| 61 | +``` |
| 62 | + |
| 63 | +</TabItem> |
| 64 | +<TabItem value="yarn"> |
| 65 | + |
| 66 | +```shell |
| 67 | +yarn start |
| 68 | +``` |
| 69 | + |
| 70 | +</TabItem> |
| 71 | +</Tabs> |
| 72 | + |
| 73 | +:::note |
| 74 | +If you're familiar with web development, Metro is similar to bundlers such as Vite and webpack, but is designed end-to-end for React Native. For instance, Metro uses [Babel](https://babel.dev/) to transform syntax such as JSX into executable JavaScript. |
| 75 | +::: |
| 76 | + |
| 77 | +### Step 3: Start your application |
| 78 | + |
| 79 | +Let Metro Bundler run in its own terminal. Open a new terminal inside your React Native project folder. Run the following: |
| 80 | + |
| 81 | +<Tabs groupId="package-manager" queryString defaultValue={constants.defaultPackageManager} values={constants.packageManagers}> |
| 82 | +<TabItem value="npm"> |
| 83 | + |
| 84 | +```shell |
| 85 | +npm run android |
| 86 | +``` |
| 87 | + |
| 88 | +</TabItem> |
| 89 | +<TabItem value="yarn"> |
| 90 | + |
| 91 | +```shell |
| 92 | +yarn android |
| 93 | +``` |
| 94 | + |
| 95 | +</TabItem> |
| 96 | +</Tabs> |
| 97 | + |
| 98 | +If everything is set up correctly, you should see your new app running in your Android emulator shortly. |
| 99 | + |
| 100 | +This is one way to run your app - you can also run it directly from within Android Studio. |
| 101 | + |
| 102 | +> If you can't get this to work, see the [Troubleshooting](troubleshooting.md) page. |
| 103 | +
|
| 104 | +### Step 4: Modifying your app |
| 105 | + |
| 106 | +Now that you have successfully run the app, let's modify it. |
| 107 | + |
| 108 | +- Open `App.tsx` in your text editor of choice and edit some lines. |
| 109 | +- Press the <kbd>R</kbd> key twice or select `Reload` from the Dev Menu (<kbd>Ctrl</kbd> + <kbd>M</kbd>) to see your changes! |
| 110 | + |
| 111 | +### That's it! |
| 112 | + |
| 113 | +Congratulations! You've successfully run and modified your first barebone React Native app. |
| 114 | + |
| 115 | +<center><img src="/docs/assets/GettingStartedCongratulations.png" width="150"></img></center> |
| 116 | + |
| 117 | +### Now what? |
| 118 | + |
| 119 | +- If you want to add this new React Native code to an existing application, check out the [Integration guide](integration-with-existing-apps.md). |
| 120 | +- If you're curious to learn more about React Native, check out the [Introduction to React Native](getting-started). |
0 commit comments