Weird result when using state variables in dialog templates

Hi! I tried to use state in dialog's header, content and footer templates. Header and Footer were showing state value but content did not. Is it possible that content template is somehow broken? If not, what am I doing wrong? Here is my code:


import React, { useState, useRef } from 'react';
import { ButtonComponent } from '@syncfusion/ej2-react-buttons';
import { DialogComponent } from '@syncfusion/ej2-react-popups';

export function Dashboard() {
const [state, setState] = useState({
dialogOpen: false,
});
const [count, setCount] = useState(0);

const handleClick = () => {
setState({ dialogOpen: true })
setCount(count + 1);
};

const handleClose = () => {
setState({ dialogOpen: false });
};

const headerTemplate = () => {
return <div>Test { count }div>
}

const contentTemplate = () => {
return <div>This dialog has been opened {count} timesdiv>
}

const footerTemplate = () => {
return <div>Footer { count }div>
}

return (
<div>
<DialogComponent
width='350px'
visible={state.dialogOpen}
header={headerTemplate}
content={contentTemplate}
footerTemplate={footerTemplate}
close={handleClose}
overlayClick={() => handleClose}
/>
<ButtonComponent onClick={handleClick}>
Open
ButtonComponent>
div>
)
}

As a side note.... if I looked at components in React dev tools there were multiple headers and footers and only one content. Which is kind of weird. Should there be so many header/footer components?

2022-08-30 (1).png


3 Replies

VJ Vinitha Jeyakumar Syncfusion Team August 31, 2022 06:48 AM UTC

Hi Janno,


We have already considered the reported issue "React state change value is not reflected inside the Dialog content template" as a bug from our end and we will update you the further details about the timeline for the fix on or before 2nd September 2022.


You can now track the status of the reported issue through the below feedback,

https://www.syncfusion.com/feedback/35110/react-state-change-value-is-not-reflected-inside-the-dialog-content-template


Until then you can use the below workaround to resolve your reported issue in sample level by using the Dialog content directly without using template,


Samplehttps://stackblitz.com/edit/react-dmy3ac?file=src%2FApp.js,src%2Fstyle.css


Regards,

Vinitha








VJ Vinitha Jeyakumar Syncfusion Team September 2, 2022 01:54 PM UTC

Hi Janno,


We will include the fix for the issue "React state change value is not reflected inside the Dialog content template" with our upcoming patch release on 13th September 2022.

Regards,
Vinitha


TJ Theveshwar Jayakumar Syncfusion Team February 20, 2023 11:36 AM UTC


Hi
Janno,

 

Sorry for the delay caused.

We are glad to announce that our Essential Studio 2022 Volume 4 release v20.4.0.38 is rolled out and is available for download under the following link.

 

https://www.syncfusion.com/forums/179561/essential-studio-2022-volume-4-main-release-v20-4-0-38-is-available-for-download

 

The issue with “React state change value is not reflected inside the Dialog content template” has been resolved in this release. To access this fix, we suggest you to update the package to the latest version 20.4.38.

 

We would like to inform you that, by default the Dialog component content will not be updated while state updates. To resolve this, we suggest to use statelessTemplates property value as empty array. This property specifies the array of the template names where the state value updates need to be ignored.

 

For your reference, we have prepared a sample in the link:  https://stackblitz.com/edit/react-ntrkyi-7maupn?file=index.js

 

Release notes:  https://ej2.syncfusion.com/react/documentation/release-notes/20.4.38/?type=all#common

 

We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.

 

Regards,

Theveshwar


Loader.
Up arrow icon