Guide to integrating the office-ui-fabric-react library into your current MVC project

Our team has embarked on developing an application and we've decided to integrate it with office-ui-fabric-react. While I am familiar with installing packages using npm, I am unsure about where to install both NodeJs & gulp.
I have a repository named Relationize, within which there are folders for my Api and web application (along with my package-lock.json).
I'm not sure if these installations should go in the root where my project file is located or in my wwwroot directory (some sources mention it should be in the root). However, when I executed all three commands: npm i -S nodejs, npm install --global gulp-cli, and finally

npm --save install office-ui-fabric-react
to install the office package. When attempting to add a component in a separate JavaScript file just to test its functionality (by copying code from @Microsoft):

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Fabric } from 'office-ui-fabric-react/lib/Fabric';
import { DefaultButton } from 'office-ui-fabric-react/lib/Button';

const MyPage = () => (<Fabric><DefaultButton>I am a button.</DefaultButton></Fabric>);

ReactDOM.render(<MyPage />, document.body.firstChild);

An error is thrown:

Uncaught SyntaxError: Unexpected token import

If anyone has a clear guide on how to implement this in an existing project or is willing to assist me through the process, your help would be greatly appreciated!

Thank you in advance!

Answer №1

It's possible that you may need to integrate build tools like babel, webpack, and others to properly convert your js file for browser compatibility. Although, your browser might already understand the latest module syntax...

If you're looking for a good example program, check out: https://medium.com/@gmonne/simple-app-layout-with-office-ui-fabric-react-2eac6361e1b4. There are also other helpful examples available.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Attempting to include a select element via transclusion

Looking to develop a custom directive named select that will replace a select element with a customized dropdown interface. For a clear example, check out this jsfiddle where the concept is demonstrated. Let's consider the below select element: < ...

Can you explain the distinction between these two npm installation commands?

To install @uiw/react-monacoeditor using npm, you can use either the command <strong>npm install @uiw/react-monacoeditor --save</strong> or simply <strong>npm i @uiw/react-monacoeditor</strong>. But what exactly is the difference ...

Responsive design involves ensuring that web elements such as divs are properly aligned

I am currently working on aligning 2 divs in a specific way that is responsive. I would like the right div to stack on top of the left div when the screen width reaches a certain point, as opposed to them both taking up 50% of the container's width. ...

Develop a custom dropdown menu using JavaScript

I've been working on creating a dropdown menu that appears after selecting an option from another dropdown menu. Here's the HTML code I'm using: <br> <select id ="select-container" onchange="addSelect('select-container') ...

What could be the reason behind my alert message not showing up when the user fails to login correctly? Exploring Django, HTML, and CSS for answers

Below is the code snippet from my signIn.html file: {% if messg %} <script> aleart("{{messg}}"); </script> {% endif %} Here is a snippet of my Django View code: def postsign(request): email = request.POST.get("email" ...

The multiplication sum is not being calculated correctly after the decimal point in JavaScript

Just dipping my toes into the world of JavaScript, so please be gentle! I'm currently working on a function that multiplies one input field by another that the user provides. However, there seems to be an issue when the user wants to multiply by 8.5 ...

Combine Immer and NgRx reducer for improved state management

Upon analyzing redux and ngrx, it appears that immer is the preferred library for creating a copy of the state before storing it. In following the example provided by immer, I implemented the following code in my reducer: on(exampleActions.updateExample ...

Why won't the div move when I click it?

Could you please explain why my JavaScript code isn't functioning as expected? The intended behavior is for the 'mark' div to move to the current mouse coordinates upon clicking within the map. ...

Clear out duplicate elements from array instruction

I am currently working with a div that displays names and I need to remove any duplicates from my array. I have successfully achieved this with a filter, but now I would like to explore creating a directive to extend this functionality. <div ng-control ...

Tips for incorporating the .click function with an overlay

Having some trouble using the .click function in conjunction with jQuery Tools overlay. HTML: <p id="click">Click here:</p> <div class="pop"> <div> <p>Insert text here</p> </div> </div> jQuery func ...

What is the best way to represent objects in a user interface?

Currently, I have some information stored in the following format: data : { full_name: 'John Doe', date_of_birth: '01-01-1990' } I am looking to display this data in a table-like format that resembles: Full Name: John Doe Date Of B ...

Leveraging Promises within if conditions

Has anyone encountered difficulties using Promises within an if condition? I'm currently dealing with a problem where the code continues to execute even when the if statement is false. Any suggestions on how to resolve this issue? For a detailed exam ...

What is the process for utilizing "yarn create <pkg-name>" command?

While browsing the Yarn blog, I came across a feature that caught my attention - yarn create. This function is similar to create-react-app. https://yarnpkg.com/blog/2017/05/12/introducing-yarn/ I decided to give it a try on my local machine by creating a ...

What is the process for creating an index signature for a type alias representing a Map in Typescript?

Suppose I have a custom type for a Map as follows: type MyCustomMap = Map<string, number>; Is there any way to add an index signature to this type so that I can set key-value pairs after initializing it? I have been able to achieve this with types ...

The display and concealment of a div will shift positions based on the sequence in which its associated buttons are clicked

I am in need of assistance with coding (I am still learning, so please excuse any syntax errors). What I am trying to achieve is having two buttons (button A and button B) that can toggle the visibility of their respective divs (div A and div B), which sh ...

Using Javascript to parse a json file that contains additional content at the beginning

I am attempting to access a JSON URL, but the JSON is displaying some extra characters before it starts. The structure of the JSON script is as follows: throw 'allowIllegalResourceCall is false.'; { "name":"mkyong", "age":30, "addres ...

Error: Unable to execute workouts.map as a function in "React" due to a TypeError

This is the JSON data retrieved from the server: {workouts: Array(3)} workouts: Array(3) 0: {_id: 'idnumber1', title: 'pullup', reps: 40, load: '20', createdAt: '2022-07-20T18:06:39.642Z', …} 1: {_id: 'idnumb ...

Import the JSON data into the designated storage unit

$(".btn-primary").click(function(){ runSuccessFunction(jsonObj); }); If I need to update the JSON data in the JSFiddle Code example, how can I reload only the container by clicking a button? I want to run the code every time I make a change to the J ...

Is it necessary to include modifications made to a package.json file when committing to a repository?

I'm uncertain about the proper way to commit and push changes in the package.JSON file to a repository. From my understanding, others working with the git repository can install new dependencies by running the command: npm install, which will automati ...

"Troubleshooting: Why Won't insertAfter Function Work with

I have a p Element that I want to wrap inside a span tag. Then, I need to insert it after another p tag with the id output. Despite my attempts, the insertAfter function is not working as expected. $mytext = $("p#test").html(); $myspan = "<span styl ...