As an example today, we're going to install Lodash and use it in our project. I'm going to run npm install --save Lodash. As you can see, this will kick off the usual install process. Now Lodash is installed. If I look at my package.json, you can see that Lodash has been added to my list of dependencies.
I'm going to go ahead and commit that change, "add lodash to dependencies." Let's go ahead and use this third-party module that we just installed. We'll pop over into our code. I'm going to import from 'lodash'. Let's actually use this. We're going to say "Your lucky number is." Then we're going to open some curly braces and call Lodash with.random. We'll ask for one of 100 lucky numbers.
For example, let's install jQuery, so npm install --save jQuery. Now we've installed jQuery. Let's go back into our code. We're going to import $ from 'jquery'. I'm going to save that. I've turned on live reload in my simulator, so that's going to refresh. You'll notice that it will take a minute for the React Native Packager to reload every time you import a new module.
Now let's go into our render method. Let's say that we want to get all of the divs in the windows using jQuery's selector API. I'm going to say var divs = $. I'm going to ask for all divs. I'm going to save this. As you can see, we get this wonderful red error screen -- jQuery requires a window with a document.
If you're working with mobile, you're not going to be wanting to interact with the browser window APIs anyway. Just about all of them should work out of the box, just like Lodash did. Now if we go back, we can see that everything is working again.