Canhua's Blog
  • Blogs
  • My GitHub Projects
  • Profile
  • Linkedin
Canhua's Blog

ES6 import

January 18, 2022

'import name from' is the right way to import json and css files in react project.

Yesterday someone complains hostconf doesn't work when they are using adaptivecards-react. After the investigation, the root cause is that she import the json file like below:

import * as dark from "./dark.json"

But actually it should be

import dark from "./dark.json"

Here is the why:

  • Importing an entire module:
import * as name from 'module-name'
  • Import default export from a module:
import name from 'module-name'

Profile picture

Written by Canhua Li Experienced Full Stack Engineer at Microsoft, proficient in C++, C#, JavaScript, React, AngularJS, Ruby & Rails, and .Net.

  • ← JavaScript Knowns 2
  • LeetCode 971 - Flip Binary Tree To Match Preorder Traversal →
© 2023, Built with Gatsby