1"use strict";(self.webpackChunkreact_native_website=self.webpackChunkreact_native_website||[]).push([["13841"],{74433(e,a,t){t.r(a),t.d(a,{metadata:()=>i,default:()=>v,frontMatter:()=>c,contentTitle:()=>d,toc:()=>p,assets:()=>u});var i=JSON.parse('{"id":"libraries","title":"Using Libraries","description":"This guide introduces React Native developers to finding, installing, and using third-party libraries in their apps.","source":"@site/../docs/libraries.md","sourceDirName":".","slug":"/libraries","permalink":"/docs/next/libraries","draft":false,"unlisted":false,"editUrl":"[{\\"label\\":\\"Edit this page\\",\\"href\\":\\"https://github.com/facebook/react-native-website/edit/main/docs/libraries.md\\"}]","tags":[],"version":"current","lastUpdatedAt":1755241972000,"frontMatter":{"id":"libraries","title":"Using Libraries","author":"Brent Vatne","authorURL":"https://twitter.com/notbrent","description":"This guide introduces React Native developers to finding, installing, and using third-party libraries in their apps."},"sidebar":"docs","previous":{"title":"Metro","permalink":"/docs/next/metro"},"next":{"title":"Using TypeScript","permalink":"/docs/next/typescript"}}'),r=t(62540),n=t(43023),l=t(77779),s=t(98263),o=t(38469);let c={id:"libraries",title:"Using Libraries",author:"Brent Vatne",authorURL:"https://twitter.com/notbrent",description:"This guide introduces React Native developers to finding, installing, and using third-party libraries in their apps."},d,u={},p=[{value:"Selecting a Package Manager",id:"selecting-a-package-manager",level:2},{value:"Installing a Library",id:"installing-a-library",level:2},{value:"Linking Native Code on iOS",id:"linking-native-code-on-ios",level:2},{value:"Linking Native Code on Android",id:"linking-native-code-on-android",level:2},{value:"Finding Libraries",id:"finding-libraries",level:2},{value:"Determining Library Compatibility",id:"determining-library-compatibility",level:2},{value:"Does it work with React Native?",id:"does-it-work-with-react-native",level:3},{value:"Does it work for the platforms that my app supports?",id:"does-it-work-for-the-platforms-that-my-app-supports",level:3},{value:"Does it work with my app version of React Native?",id:"does-it-work-with-my-app-version-of-react-native",level:3}];function h(e){let a={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",h3:"h3",p:"p",pre:"pre",...(0,n.R)(),...e.components};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)(a.p,{children:["React Native provides a set of built-in ",(0,r.jsx)(a.a,{href:"./components-and-apis",children:"Core Components and APIs"})," ready to use in your app. You're not limited to the components and APIs bundled with React Native. React Native has a community of thousands of developers. If the Core Components and APIs don't have what you are looking for, you may be able to find and install a library from the community to add the functionality to your app."]}),"\n",(0,r.jsx)(a.h2,{id:"selecting-a-package-manager",children:"Selecting a Package Manager"}),"\n",(0,r.jsxs)(a.p,{children:["React Native libraries are typically installed from the ",(0,r.jsx)(a.a,{href:"https://www.npmjs.com/",children:"npm registry"})," using a Node.js package manager such as ",(0,r.jsx)(a.a,{href:"https://docs.npmjs.com/cli/npm",children:"npm CLI"})," or ",(0,r.jsx)(a.a,{href:"https://classic.yarnpkg.com/en/",children:"Yarn Classic"}),"."]}),"\n",(0,r.jsx)(a.p,{children:"If you have Node.js installed on your computer then you already have the npm CLI installed. Some developers prefer to use Yarn Classic for slightly faster install times and additional advanced features like Workspaces. Both tools work great with React Native. We will assume npm for the rest of this guide for simplicity of explanation."}),"\n",(0,r.jsx)(a.admonition,{type:"note",children:(0,r.jsx)(a.p,{children:'The terms "library" and "package" are used interchangeably in the JavaScript community.'})}),"\n",(0,r.jsx)(a.h2,{id:"installing-a-library",children:"Installing a Library"}),"\n",(0,r.jsxs)(a.p,{children:["To install a library in your project, navigate to your project directory in your terminal and run the installation command. Let's try this with ",(0,r.jsx)(a.code,{children:"react-native-webview"}),":"]}),"\n",(0,r.jsxs)(l.A,{groupId:"package-manager",queryString:!0,defaultValue:o.A.defaultPackageManager,values:o.A.packageManagers,children:[(0,r.jsx)(s.A,{value:"npm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"npm install react-native-webview\n"})})}),(0,r.jsx)(s.A,{value:"yarn",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"yarn add react-native-webview\n"})})})]}),"\n",(0,r.jsx)(a.p,{children:"The library that we installed includes native code, and we need to link to our app before we use it."}),"\n",(0,r.jsx)(a.h2,{id:"linking-native-code-on-ios",children:"Linking Native Code on iOS"}),"\n",(0,r.jsx)(a.p,{children:"React Native uses CocoaPods to manage iOS project dependencies and most React Native libraries follow this same convention. If a library you are using does not, then please refer to their README for additional instruction. In most cases, the following instructions will apply."}),"\n",(0,r.jsxs)(a.p,{children:["Run ",(0,r.jsx)(a.code,{children:"pod install"})," in our ",(0,r.jsx)(a.code,{children:"ios"})," directory in order to link it to our native iOS project. A shortcut for doing this without switching to the ",(0,r.jsx)(a.code,{children:"ios"})," directory is to run ",(0,r.jsx)(a.code,{children:"npx pod-install"}),"."]}),"\n",(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-bash",children:"npx pod-install\n"})}),"\n",(0,r.jsx)(a.p,{children:"Once this is complete, re-build the app binary to start using your new library:"}),"\n",(0,r.jsxs)(l.A,{groupId:"package-manager",queryString:!0,defaultValue:o.A.defaultPackageManager,values:o.A.packageManagers,children:[(0,r.jsx)(s.A,{value:"npm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"npm run ios\n"})})}),(0,r.jsx)(s.A,{value:"yarn",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"yarn ios\n"})})})]}),"\n",(0,r.jsx)(a.h2,{id:"linking-native-code-on-android",children:"Linking Native Code on Android"}),"\n",(0,r.jsx)(a.p,{children:"React Native uses Gradle to manage Android project dependencies. After you install a library with native dependencies, you will need to re-build the app binary to use your new library:"}),"\n",(0,r.jsxs)(l.A,{groupId:"package-manager",queryString:!0,defaultValue:o.A.defaultPackageManager,values:o.A.packageManagers,children:[(0,r.jsx)(s.A,{value:"npm",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"npm run android\n"})})}),(0,r.jsx)(s.A,{value:"yarn",children:(0,r.jsx)(a.pre,{children:(0,r.jsx)(a.code,{className:"language-shell",children:"yarn android\n"})})})]}),"\n",(0,r.jsx)(a.h2,{id:"finding-libraries",children:"Finding Libraries"}),"\n",(0,r.jsxs)(a.p,{children:[(0,r.jsx)(a.a,{href:"https://reactnative.directory",children:"React Native Directory"})," is a searchable database of libraries built specifically for React Native. This is the first place to look for a library for your React Native app."]}),"\n",(0,r.jsxs)(a.p,{children:["Many of the libraries you will find on the directory are from ",(0,r.jsx)(a.a,{href:"https://github.com/react-native-community/",children:"React Native Community"})," or ",(0,r.jsx)(a.a,{href:"https://docs.expo.dev/versions/latest/",children:"Expo"}),"."]}),"\n",(0,r.jsx)(a.p,{children:"Libraries built by the React Native Community are driven by volunteers and individuals at companies that depend on React Native. They often support iOS, tvOS, Android, Windows, but this varies across projects. Many of the libraries in this organization were once React Native Core Components and APIs."}),"\n",(0,r.jsxs)(a.p,{children:["Libraries built by Expo are all written in TypeScript and support iOS, Android, and ",(0,r.jsx)(a.code,{children:"react-native-web"})," wherever possible."]}),"\n",(0,r.jsxs)(a.p,{children:["After React Native Directory, the ",(0,r.jsx)(a.a,{href:"https://www.npmjs.com/",children:"npm registry"})," is the next best place if you can't find a library specifically for React Native on the directory. 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."]}),"\n",(0,r.jsx)(a.h2,{id:"determining-library-compatibility",children:"Determining Library Compatibility"}),"\n",(0,r.jsx)(a.h3,{id:"does-it-work-with-react-native",children:"Does it work with React Native?"}),"\n",(0,r.jsxs)(a.p,{children:["Usually libraries built ",(0,r.jsx)(a.em,{children:"specifically for other platforms"})," will not work with React Native. Examples include ",(0,r.jsx)(a.code,{children:"react-select"})," which is built for the web and specifically targets ",(0,r.jsx)(a.code,{children:"react-dom"}),", and ",(0,r.jsx)(a.code,{children:"rimraf"})," which is built for Node.js and interacts with your computer file system. Other libraries like ",(0,r.jsx)(a.code,{children:"lodash"})," use only JavaScript language features and work in any environment. You will gain a sense for this over time, but until then the easiest way to find out is to try it yourself. You can remove packages using ",(0,r.jsx)(a.code,{children:"npm uninstall"})," if it turns out that it does not work in React Native."]}),"\n",(0,r.jsx)(a.h3,{id:"does-it-work-for-the-platforms-that-my-app-supports",children:"Does it work for the platforms that my app supports?"}),"\n",(0,r.jsxs)(a.p,{children:[(0,r.jsx)(a.a,{href:"https://reactnative.directory",children:"React Native Directory"})," allows you to filter by platform compatibility, such as iOS, Android, Web, and Windows. If the library you would like to use is not currently listed there, refer to the README for the library to learn more."]}),"\n",(0,r.jsx)(a.h3,{id:"does-it-work-with-my-app-version-of-react-native",children:"Does it work with my app version of React Native?"}),"\n",(0,r.jsxs)(a.p,{children:["The latest version of a library is typically compatible with the latest version of React Native. If you are using an older version, you should refer to the README to know which version of the library you should install. You can install a particular version of the library by running ",(0,r.jsx)(a.code,{children:"npm install <library-name>@<version-number>"}),", for example: ",(0,r.jsx)(a.code,{children:"npm install @react-native-community/netinfo@^2.0.0"}),"."]})]})}function v(e={}){let{wrapper:a}={...(0,n.R)(),...e.components};return a?(0,r.jsx)(a,{...e,children:(0,r.jsx)(h,{...e})}):h(e)}},98263(e,a,t){t.d(a,{A:()=>s});var i=t(62540);t(63696);var r=t(11750),n=t(23865);function l({children:e,className:a,hidden:t}){return(0,i.jsx)("div",{role:"tabpanel",className:(0,r.A)("tabItem_wHwb",a),hidden:t,children:e})}function s({children:e,className:a,value:t}){let{selectedValue:r,lazy:o}=(0,n.uc)(),c=t===r;return!c&&o?null:(0,i.jsx)(l,{className:a,hidden:!c,children:e})}},77779(e,a,t){t.d(a,{A:()=>p});var i=t(62540);t(63696);
1var r=t(11750),n=t(46065),l=t(23865),s=t(45194),o=t(83029);function c({className:e}){let{selectedValue:a,selectValue:t,tabValues:n,block:o}=(0,l.uc)(),d=[],{blockElementScrollPositionUntilNextRender:u}=(0,s.a_)(),p=e=>{let i=e.currentTarget,r=n[d.indexOf(i)].value;r!==a&&(u(i),t(r))},h=e=>{let a=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{let t=d.indexOf(e.currentTarget)+1;a=d[t]??d[0];break}case"ArrowLeft":{let t=d.indexOf(e.currentTarget)-1;a=d[t]??d[d.length-1]}}a?.focus()};return(0,i.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,r.A)("tabs",{"tabs--block":o},e),children:n.map(({value:e,label:t,attributes:n})=>(0,i.jsx)("li",{role:"tab",tabIndex:a===e?0:-1,"aria-selected":a===e,ref:e=>{d.push(e)},onKeyDown:h,onClick:p,...n,className:(0,r.A)("tabs__item","tabItem_l0OV",n?.className,{"tabs__item--active":a===e}),children:t??e},e))})}function d({children:e}){return(0,i.jsx)("div",{className:"margin-top--md",children:e})}function u({className:e,children:a}){return(0,i.jsxs)("div",{className:(0,r.A)(n.G.tabs.container,"tabs-container","tabList_J5MA"),children:[(0,i.jsx)(c,{className:e}),(0,i.jsx)(d,{children:a})]})}function p(e){let a=(0,o.A)(),t=(0,l.OC)(e);return(0,i.jsx)(l.O_,{value:t,children:(0,i.jsx)(u,{className:e.className,children:(0,l.vT)(e.children)})},String(a))}},23865(e,a,t){t.d(a,{OC:()=>p,O_:()=>m,uc:()=>v,vT:()=>d});var i=t(62540),r=t(63696),n=t(49519),l=t(6743),s=t(88511),o=t(15396),c=t(89030);function d(e){return r.Children.toArray(e).filter(e=>"\n"!==e)}function u({value:e,tabValues:a}){return a.some(a=>a.value===e)}function p(e){let a,{defaultValue:t,queryString:i=!1,groupId:d}=e,p=function(e){let{values:a,children:t}=e;return(0,r.useMemo)(()=>{let e=a??r.Children.toArray(t).flatMap(e=>{if(!e)return[];if((0,r.isValidElement)(e)&&function(e){let{props:a}=e;return!!a&&"object"==typeof a&&"value"in a}(e))return[e];let a="string"==typeof e.type?e.type:e.type.name;throw Error(`Docusaurus error: Bad <Tabs> child <${a}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop. 2If you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.`)}).map(({props:{value:e,label:a,attributes:t,default:i}})=>({value:e,label:a,attributes:t,default:i})),i=(0,o.XI)(e,(e,a)=>e.value===a.value);if(i.length>0)throw Error(`Docusaurus error: Duplicate values "${i.map(e=>`'${e.value}'`).join(", ")}" found in <Tabs>. Every value needs to be unique.`);return e},[a,t])}(e),[h,v]=(0,r.useState)(()=>(function({defaultValue:e,tabValues:a}){if(0===a.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(e){if(!u({value:e,tabValues:a}))throw Error(`Docusaurus error: The <Tabs> has a defaultValue "${e}" but none of its children has the corresponding value. Available values are: ${a.map(e=>e.value).join(", ")}. If you intend to show no default tab, use defaultValue={null} instead.`);return e}let t=a.find(e=>e.default)??a[0];if(!t)throw Error("Unexpected error: 0 tabValues");return t.value})({defaultValue:t,tabValues:p})),[m,f]=function({queryString:e=!1,groupId:a}){let t=(0,n.W6)(),i=function({queryString:e=!1,groupId:a}){if("string"==typeof e)return e;if(!1===e)return null;if(!0===e&&!a)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return a??null}({queryString:e,groupId:a});return[(0,s.aZ)(i),(0,r.useCallback)(e=>{if(!i)return;let a=new URLSearchParams(t.location.search);a.set(i,e),t.replace({...t.location,search:a.toString()})},[i,t])]}({queryString:i,groupId:d}),[b,g]=function({groupId:e}){let a=e?`docusaurus.tab.${e}`:null,[t,i]=(0,c.Dv)(a);return[t,(0,r.useCallback)(e=>{a&&i.set(e)},[a,i])]}({groupId:d}),y=u({value:a=m??b,tabValues:p})?a:null;return(0,l.A)(()=>{y&&v(y)},[y]),{selectedValue:h,selectValue:(0,r.useCallback)(e=>{if(!u({value:e,tabValues:p}))throw Error(`Can't select invalid tab value=${e}`);v(e),f(e),g(e)},[f,g,p]),tabValues:p,lazy:e.lazy??!1,block:e.block??!1}}let h=(0,r.createContext)(null);function v(){let e=r.useContext(h);if(!e)throw Error("useTabsContext() must be used within a Tabs component");return e}function m(e){return(0,i.jsx)(h.Provider,{value:e.value,children:e.children})}},38469(e,a,t){t.d(a,{A:()=>l});var i=t(93227);let r=!!i.A.canUseDOM&&navigator.platform.startsWith("Mac"),n=!!i.A.canUseDOM&&navigator.platform.startsWith("Win"),l={defaultGuide:"quickstart",defaultJsDebugger:"flipper",defaultOs:r?"macos":n?"windows":"linux",defaultPackageManager:"npm",defaultPlatform:r?"ios":"android",defaultSyntax:"functional",defaultAndroidLanguage:"java",defaultAppleLanguage:"objc",defaultJavaScriptSpecLanguages:"typescript",getDevNotesTabs:(e=["android","ios","web","windows"])=>[e.includes("android")?{label:"Android",value:"android"}:void 0,e.includes("ios")?{label:"iOS",value:"ios"}:void 0,e.includes("web")?{label:"Web",value:"web"}:void 0,e.includes("windows")?{label:"Windows",value:"windows"}
2:void 0].filter(Boolean),guides:[{label:"Expo Go Quickstart",value:"quickstart"},{label:"React Native CLI Quickstart",value:"native"}],oses:[{label:"macOS",value:"macos"},{label:"Windows",value:"windows"},{label:"Linux",value:"linux"}],packageManagers:[{label:"npm",value:"npm"},{label:"Yarn",value:"yarn"}],platforms:[{label:"Android",value:"android"},{label:"iOS",value:"ios"}],syntax:[{label:"Function Component",value:"functional"},{label:"Class Component",value:"classical"}],androidLanguages:[{label:"Java",value:"java"},{label:"Kotlin",value:"kotlin"}],appleLanguages:[{label:"ObjectiveC",value:"objc"},{label:"Swift",value:"swift"}],javaScriptSpecLanguages:[{label:"TypeScript",value:"typescript"},{label:"Flow",value:"flow"}],jsDebuggers:[{label:"Hermes Debugger / Expo",value:"hermes"},{label:"Flipper",value:"flipper"},{label:"New Debugger (Experimental)",value:"new-debugger"}],snackLanguages:[{label:"TypeScript",value:"typescript"},{label:"JavaScript",value:"javascript"}],defaultSnackLanguage:"typescript"}},43023(e,a,t){t.d(a,{R:()=>l,x:()=>s});var i=t(63696);let r={},n=i.createContext(r);function l(e){let a=i.useContext(n);return i.useMemo(function(){return"function"==typeof e?e(a):{...a,...e}},[a,e])}function s(e){let a;return a=e.disableParentContext?"function"==typeof e.components?e.components(r):e.components||r:l(e.components),i.createElement(n.Provider,{value:a},e.children)}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.