1

I'm a beginner in the new Javascript world and would like to know the difference between

import { MessageBar } from "office-ui-fabric-react";

import { MessageBar } from "office-ui-fabric-react/lib-commonjs/MessageBar";

Both of them seem to work fine. I'm using webpack for creating final JS files. What is the recommended way to import components?

Gopal
  • 1,292
  • 3
  • 19
  • 41

1 Answers1

1

Both should work. The first one allows you to aggregate all your imports in a single expression.

Note that UI Fabric is deprecated and you should switch to Fluent UI React or Fluent UI React Northstar. So for example your import could look like this:

import { DatePicker, MessageBar } from '@fluentui/react';
Christophe
  • 27,383
  • 28
  • 97
  • 140
  • 1
    Thanks @Christophe. Why is it that there are different folders for AMD/CommonJS etc? – Gopal Feb 22 '21 at 16:41
  • I am no expert here, but I would assume the transpiler will pick one or the other depending on your target (Web, Nodejs, etc.), based on what config options you select. – Christophe Feb 22 '21 at 19:25