1--- 2title: Use libraries 3description: Learn how to use libraries based on React Native, Expo SDK and third-party in your project. 4--- 5 6import { ConfigReactNative } from '~/components/plugins/ConfigSection'; 7import PlatformsSection from '~/components/plugins/PlatformsSection'; 8import InstallSection from '~/components/plugins/InstallSection'; 9import { BoxLink } from '~/ui/components/BoxLink'; 10import { Terminal } from '~/ui/components/Snippet'; 11import { SnackInline } from '~/ui/components/Snippet'; 12 13Every app is inevitably going to use a third-party library, so it's important to understand how to determine whether a library is compatible with your project. 14 15## React Native core libraries 16 17React Native provides a set of built-in primitives that most developers will need in their apps. These include components such as `<ActivityIndicator>`, `<TextInput>`, `<Text>`, `<ScrollView>`, and `<View>`. These are listed at [Core Components and APIs](https://reactnative.dev/docs/components-and-apis) in React Native documentation. You can also view the [React Native version that corresponds to your Expo SDK version](/versions/latest). 18 19To use a React Native component or API in your project, import it from the `react-native` package in your code: 20 21<SnackInline> 22 23```jsx 24import * as React from 'react'; 25import { Text, View } from 'react-native'; 26 27export default function App() { 28 return ( 29 <View style={{ flex: 1, paddingTop: 100 }}> 30 <Text>Hello, world!</Text> 31 </View> 32 ); 33} 34``` 35 36</SnackInline> 37 38## Expo SDK libraries 39 40The Expo SDK picks up where the React Native core libraries end. It provides access to a lot of device and system functionality such as audio, barcode scanning, camera, calendar, contacts, video, and so on. It also adds other powerful libraries like updates, maps, OAuth authentication tools, and more. For more information, see how we decide [what goes into the Expo SDK](https://expo.fyi/whats-in-the-sdk). 41 42To use a library from the Expo SDK, find the one you are looking for in the [API Reference](/versions/latest/) or through the documentation Search bar. 43 44<ConfigReactNative> 45 46If you initialized your app using `npx react-native init` and you don't have the `expo` package installed in it yet, refer to the [installing Expo modules guide](/bare/installing-expo-modules). 47 48</ConfigReactNative> 49 50At the top of the page you will see a description of the library and a platform compatibility table. It tells you which platforms and environments the library is compatible with. It looks like this: 51 52<PlatformsSection android emulator ios simulator web /> 53 54After the platform compatibility table, there will be an Installation section, with instructions that look like this: 55 56<InstallSection packageName="expo-device" hideBareInstructions /> 57 58The `npx expo install` command will pick a version of the library that is compatible with your project and then use your JavaScript package manager (such as npm) to install it. 59 60Next, under the API section the reference page will tell you how to import the library in your code: 61 62```js 63import * as Device from 'expo-device'; 64``` 65 66This section also lists all of the types, functions, and classes available. If you use TypeScript, you can see this information in your TypeScript-compatible code editor (such as Visual Studio Code) with auto-completion. 67 68Now you can use the library in your project: 69 70<SnackInline dependencies={['expo-device']}> 71 72```jsx 73import * as React from 'react'; 74import { Text, View } from 'react-native'; 75import * as Device from 'expo-device'; 76 77export default function App() { 78 return ( 79 <View style={{ flex: 1, paddingTop: 100 }}> 80 <Text> 81 {Device.manufacturer}: {Device.modelName} 82 </Text> 83 </View> 84 ); 85} 86``` 87 88</SnackInline> 89 90## Third-Party libraries 91 92### Finding a third-party library 93 94[React Native Directory](https://reactnative.directory) is a searchable database of libraries built specifically for React Native. If the library that you are looking for is not provided by React Native or the Expo SDK then this is the best place to look first when trying to find a library for your app. 95 96After React Native Directory, the [npm registry](https://www.npmjs.com/) is the next best place. The npm registry is the definitive source for JavaScript libraries, but the libraries that it lists may not all be compatible with React Native. React Native is one of many JavaScript programming environments, including Node.js, web browsers, Electron, and more, and npm includes libraries that work for all of these environments. Other libraries may be compatible with React Native, but not compatible with the [Expo Go][expo-go] app. How do you figure this out? 97 98### Determining third-party library compatibility 99 100**Check React Native Directory**: find the library on the website (if it's there) and verify that it has a "✔️ Expo Go" tag. You can also enable the [filter by Expo Go](https://reactnative.directory/?expo=true). 101 102**Not listed on the directory?** find the project on GitHub, an easy way to do this is with `npx npm-home --github <package-name>`. For example, to open the GitHub page for `react-native-localize` you would run: 103 104<Terminal cmd={['$ npx npm-home --github react-native-localize']} /> 105 106Now check the following: 107 108- Does it include an `ios` and/or `android/` directory? 109- Does the README mention linking? 110- Is it built specifically for Node.js, the web, electron, or another platform? 111 112If you answered yes to any of these questions and the library is not part of the Expo SDK, this library may not be supported in [Expo Go][expo-go]. You can go ahead and try it in a new project to be sure. Run `npx create-expo-app` and add the library to the new project and try to use it. This is a great way to experiment with a library before including it in your project in all circumstances. 113 114Many React Native libraries are not compatible with [Expo Go][expo-go]. For these libraries, you can create a [development build](/develop/development-builds/introduction/): 115 116<BoxLink 117 title="Adding custom native code" 118 description="Learn how to create a development build." 119 href="/workflow/customizing" 120/> 121 122> If you want some help determining library compatibility, [create an issue on the React Native Directory repository](https://github.com/react-native-community/directory/issues/new/choose) and let us know. This will not just help you, it will also help other developers have an easy answer in the future! 123 124### Installing a third-party library 125 126> We recommend always using `npx expo install` instead of `npm install` or `yarn add` directly because it allows [Expo CLI][expo-cli] to pick a compatible version of a library when possible and also warn you about known incompatibilities. 127 128Once you have determined if the library is compatible with React Native, use [Expo CLI][expo-cli] to install the package: 129 130<Terminal cmd={['$ npx expo install @react-navigation/native']} /> 131 132Be sure to follow the project website or README for any additional configuration and usage instructions. You can get to the README quickly using this command: 133 134<Terminal cmd={['$ npx npm-home @react-navigation/native']} /> 135 136If the module needs additional native configuration, you can do so using [config plugins](/config-plugins/introduction/). Some packages require a config plugin but they don't have one yet, you can refer to the list of [out-of-tree config plugins](https://github.com/expo/config-plugins/). 137 138<ConfigReactNative> 139 140If your project does not support [Expo Prebuild](/workflow/prebuild) then you won't be able to use [config plugins](/config-plugins/introduction/). You can either [adopt Expo Prebuild](/guides/adopting-prebuild) or set up and configure each library manually by following any additional setup guides from the respective module's website or README. 141 142</ConfigReactNative> 143 144If the module is not supported in [Expo Go][expo-go], you can create a [development build](/develop/development-builds/introduction/): 145 146<BoxLink 147 title="Adding custom native code" 148 description="Learn how to create a development build." 149 href="/workflow/customizing" 150/> 151 152[expo-cli]: /more/expo-cli/ 153[expo-go]: https://expo.dev/expo-go 154