Skip to content
Advertisement

How to properly use Modal in Fluent UI

I am new to React and Fluent UI, I loaded all my files from CDNs, when I tried execute the following code, the modal didn’t open. Please tell me what I am doing wrong here. I searched up examples but wasn’t able to find one. Here is the code:

JavaScript
JavaScript

Thanks in advance

Advertisement

Answer

If you use isModalOpen = true/false React will never know that it is supposed to re-render the view. React offers the useState hook to store state. You can then call the setter to update the value and notify React that it has to re-render the component.

You may only call hooks inside components and custom hooks. So we have to convert the function app into a component. This is simply done by changing the name of the function to start with a capital letter.

From Components and Props:

Note: Always start component names with a capital letter.

React treats components starting with lowercase letters as DOM tags. For example, <div /> represents an HTML div tag, but <Welcome /> represents a component and requires Welcome to be in scope.

To learn more about the reasoning behind this convention, please read JSX In Depth.

After making this change we also need to update the way we call App. Instead of passing app() to ReactDOM.render() we now pass <App />.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement