PeaceOfCode
PeaceOfCode

Reputation: 41

React Native Movies Example SearchBar

I have doubt that why in SearchScreen.js has this code line:

var SearchBar = require('SearchBar');

But I don't see any file SearchBar.js, only see SearchBar.android.js and SearchBar.ios.js. I don't understand why it can run ?

Upvotes: 0

Views: 1455

Answers (2)

Kacper
Kacper

Reputation: 21

You'll find the answer in the React Native documentation:

Platform Specific Code

Platform specific extensions React Native will detect when a file has a .ios. or .android. extension and load the right file for each platform when requiring them from other components.

For example, you can have these files in your project:

BigButton.ios.js

BigButton.android.js

With this setup, you can just require the files from a different component without paying attention to the platform in which the app will run.

var BigButton = require('./components/BigButton');

React Native will import the correct component for the running platform.

Upvotes: 2

Marco Argentieri
Marco Argentieri

Reputation: 31

try this you must use absolute path

var SearchBar = require('./searchBar');

Upvotes: 0

Related Questions