Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sdrucker
Microsoft Employee
Microsoft Employee

react

Has anyone used React to develop a custom visual? I'm running into various problems in getting started. Namely, I'm gettting typescript errors on the typings for react and react-dom as well as not generating a visual with the appropriate GUID as a property. 

 

1 ACCEPTED SOLUTION
sdrucker
Microsoft Employee
Microsoft Employee

I got this workaround from David Tittsworth...Thanks! 

 

Add a global.js file with contents:

var React = window.React;

var ReactDOM = window.ReactDOM;

 

and then in pbiviz.json, add a reference to the global.js file in externalJS at the bottom.

 

This works! 

View solution in original post

8 REPLIES 8
Muesli
Advocate I
Advocate I

I know your issue is about 6 month old but i am having the problem but right at the beginning. 
Could you help to install react? 

Did you install it over "npm install --save react" and "typings install --save dt~react" and how did you added all togther in your pbiviz.json and tsconfig.json? 

 

(if you can it would be cool to see your source code <3)


Greetings 

v-viig
Community Champion
Community Champion

Hello @Muesli

 

Please take a look at powerbi-visuals-react-sample as an example.

 

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

v-viig
Community Champion
Community Champion

Hello @sdrucker,

 

As far as I know Network Navigator uses React. However, it based on the legacy API.

In other words, you might face some issues using React with the new Power BI Custom Visuals API.

 

Could you please send an error message to investigate the issue that you have faced?

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

 

sdrucker
Microsoft Employee
Microsoft Employee

My first problem was getting 'pbiviz start' to compile the visual. I kept getting this error: 

 error  TYPESCRIPT  /visualPlugin.ts : (8,110) Property 'PBI_CV_1DD29A27_0A88_4642_A960_1B0EEF3F48C2' does not exist on type 'typeof visual'. (The GUID is the one that I specify in my pbiviz.json file for the visual's guid.

 

I'm not sure where the guid get's appended to the visual, but it wasn't doing that when I changed the visual.ts file to visual.tsx.

I was able to get around that by explicitly naming my module the following: 

module powerbi.extensibility.visual.PBI_CV_1DD29A27_0A88_4642_A960_1B0EEF3F48C2
 
 That's not a great solution though as it doesn't automatically recompile on changes.
 
My next (and current) problem is that in my visual's update routine, I'm calling a ReactDOM.render, and it doesn't seem to be rendering anything. (I've tried something simple - 
ReactDOM.render(<div> This is a test </div>, this.target); but that's not working. It might be the way that I'm loading the react-library, which is in pbiviz.json  under external files. 
 
Still debugging, and unfortunately, it looks like the old network navigator does use the legacy API. 
If anybody has a solution, that would be great, if not, I'll post what I find...
--Steven

I've verified that the problem is that React and ReactDOM are not being added correctly even though I've added the files to the externalJS line of pbivis.json. Not sure why this isn't working. Any opinions? 

Some more information: After looking around, I found people having similar problems. Their solution was found here:

https://github.com/Microsoft/PowerBI-visuals/issues/99 

Essentially, when react is loaded, it's put onto a window object which, (due to sandboxing?) is mucked with and not available at the update call. 

By saving the window in the constructor ( this.window = window;), I can later on do this in the update:

this.window.ReactDOM.render(this.window.React.createElement("div", null, " React test "), this.target);
 
This works! But is dissatisfying because when compiling the following jsx code
this.window.ReactDOM.render(<div> React Test </div>, this.target) 
it will produce:
this.window.ReactDOM.render(React.createElement("div", null, " React test "), this.target);
 
So, my question is now, why does d3 get elevated to a global that I can get to from the Custom Visual's update routine, but React or other external libraries aren't?
v-viig
Community Champion
Community Champion

@sdrucker

 

Power BI creates a copy of the window object in order to isolate custom visual's libraries from its own.

D3 works well due to special logic that binds d3 to the global context.

 

I suppose that we will get rid of isolation to simplify using external libraries.

 

Ignat Vilesov,

Software Engineer

 

Microsoft Power BI Custom Visuals

pbicvsupport@microsoft.com

sdrucker
Microsoft Employee
Microsoft Employee

I got this workaround from David Tittsworth...Thanks! 

 

Add a global.js file with contents:

var React = window.React;

var ReactDOM = window.ReactDOM;

 

and then in pbiviz.json, add a reference to the global.js file in externalJS at the bottom.

 

This works! 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors