Categories
- Post authorBy John Au-Yeung
- Post dateMay 1, 2022
- No Comments on How to import JSON file in React?
Spread the love
Sometimes, we want to import JSON file in React.
In this article, we’ll look at how to import JSON file in React.
How to import JSON file in React?
To import JSON file in React, we use import
to import it like a regular module.
For instance, we write
import Profile from "./components/profile";
to import the ./components/profile JSON file as Profile
.
This works because the json-loader
Webpack module is included with create-react-app
.
Conclusion
To import JSON file in React, we use import
to import it like a regular module.
Related Posts
How to import a JSON file in TypeScript?
Sometimes, we want to import a JSON file in TypeScript. In this article, we'll look…
How to import a CSS file in a React Component?
Sometimes, we want to import a CSS file in a React Component. In this article,…
How to mock import of JSON file with Jest?
Sometimes, we want to mock import of JSON file with Jest. In this article, we'll…
By John Au-Yeung
Web developer specializing in React, Vue, and front end development.