ScanSkill

How to Import the Npm Package in React?

In this example, we will see how to import the npm package in react. We can use the import statement for importing the npm package or components in react.

Prerequisites

Example

import axios from 'axios'
//OR
import {useState} from 'react'

If we need to use a whole package as a single function then we should import it as import PACKAGENAME from 'pathname' else if we need a specific function from a package or component then we should wrap the PACKAGENAME inside the curly brace like import {PACKAGENAME} from 'pathname' OR we can import a function as

import * as React from 'react'

and use its functions using a dot as React.useState().

Conclusion

In this example, we learned how to import the npm package in react. We used the import statement for importing the npm package or components in react.