What exactly does "react-native link" do?

Viewed 2209

My understanding is that if you have a native module, 'react-native link' allows you to use that module in your project. If you have some insight on any of the following questions, please do share:

1) I've seen that running 'react-native link' adds the corresponding .xcodeproj file to the Libraries folder in xcode, but how does this allow you to use the module in your project? And what does running 'react-native link' do besides add this file to this folder?

2) The components that React Native comes with out-of-the-box like , those access native functionality too, right? But we don't have to link them. Does this mean they're linked by default?

3) If those components ^^ like do come pre-linked, why can't we do this with new native modules that we install? I assume that running 'react-native link' adds something to the project that is machine-specific, but which machine would that be? The one I'm developing on?

Thanks :)

1 Answers

1) By Linking, i do believe it kind of copy/install/put together the necessary files for the module(s) and import/add those dependencies into the relevant Android and iOS specific folders/files which's what make them work and be available to the RN project.

2) Not sure but those Components act like a set of defaults which comes built-in in the RN package. It may also be seen as a set of Blocks that the RN team decided to ship together. I think there's no problem in seeing/threating them as default linked modules.

3) Newly added native modules must be linked because they are out of the "default scope" of the project and in order to be available to the RN platform, they must follow the linking process. Although it's not fun to link every single module, sometimes it's necessary, especially if you modify the default boot routine/sequence

Hope it helps ^.^

Related