Event handlers are not getting called when using React.StrictMode on React 18.0.2
See original GitHub issuePackages used:
powerbi-client: 2.21.1 powerbi-client-react: 1.3.5 react: 18.2.0 react-dom: 18.2.0
Problem description
After updating from React 17 to React 18, I noticed that event handlers were not getting called. I proceeded to remove <React.StrictMode>, and everything worked as expected.
Steps to reproduce
<PowerBIEmbed
embedConfig={{
type: "report",
tokenType: TokenType.Aad,
settings: {
personalBookmarksEnabled: true,
background: BackgroundType.Transparent,
panes: {
filters: {
visible: false,
},
pageNavigation: {
visible: false,
},
},
},
accessToken: "<token>",
embedUrl: "<embedUrl>",
}}
eventHandlers={new Map([
["loaded", () => {console.log("Report loaded")}],
])
}
/>
Expected result: “Report Loaded” get’s printed in the console. Actual result: Report renders correctly, but nothing is logged in the console.
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Strict Mode - React
StrictMode is a tool for highlighting potential problems in an application. Like Fragment , StrictMode does not render any visible UI.
Read more >javascript - React.StrictMode seems to work differently in ...
I got a solution here, where it's saying to remove the React.StrictMode from index.js and after doing so it's working fine. Then I...
Read more >React 18 New Features – Concurrent Rendering, Automatic ...
Strict mode will ensure components are resilient to effects being mounted and unmounted multiple times.
Read more >React 18 Upgrade Guide and New Features - Refine Dev
By executing the following commands in a terminal of your working directory, you can upgrade or install React 18 using NPM or Yarn...
Read more >What's New in React 18 - AppSignal Blog
To ensure you migrate your app properly, try enabling strict mode. Strict mode will let you know what is happening with components in ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I came across the same issue. Upgraded to React 18 and event handlers didn’t fire at all. I should have googled before. thanks @BrianUribe6 for logging this.
I just ran into the same issue.
I’ve been playing with the component and found this solution that seems to work with React v18 and StrictMode.
It grabs the embedded component instance and uses the “.on” method for the component to add the handler. I also did the cleanup manually with the “.off” in the return of the useEffect as I’m not sure if it automatically cleans up the handlers.