go back

import React from react vs import * as React from react

React uses CommonJs module system so we cannot use

import React from "react"

We can use this line and there is no error because Babel tries to take care of this so that we don't have to. On typescript, we use allowSyntheticDefaultImports to true so this masks the above behavior.

The idea is you do not need to write code like this

import * as React from "react"
import {Children} from "react"

Just use babel or typescript with "allowSyntheticDefaultImports": true to use the cleaner syntax.

#react #commonjs #typescript
Copyright © 2021 Bisvarup Mukherjee
counter freeViews