Using NPM Module in React Native

In the last post we discussed about passing props and displayed all the tasks present in `ListItem` inside its parent Component — `MyTaskList`. In this post we’ll go through usage of NPM module to display today’s date.

What is NPM

Simply put NPM is a dependency management system. It helps us use the code written by other developers to use in our project to solve a particular problem. Earlier we had used `npm` to install React Native Project Generator. Now we’ll use `Moment.js` library to handle date.

Importing the Module

In the terminal traverse to the project directory and enter the following command:

Terminal Screenshot

It will reach NPM registry and install latest version of `Moment`. Now let’s import `Momnent` into our React Native project. Open up the `index.ios.js` file and update the import code with the following:

Displaying Date

To display the date, we’ll update the render method with the following:

Here is the final code:

Here is how it looks in the simulator:

In the next post, we’ll learn about child component to parent component communication.

Like what you read? Give Preetish Panda a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.