mirror of
https://github.com/AustinKelsay/plebdevs.git
synced 2025-06-05 00:32:03 +00:00
capture zapRef current fo cleanup in ZapThreadsWrapper
This commit is contained in:
parent
70e31bfe91
commit
02caab317c
@ -9,6 +9,9 @@ const ZapThreadsWrapper = ({ anchor, user, relays, disable, className, isAuthori
|
|||||||
if (!isAuthorized) {
|
if (!isAuthorized) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Store the current value of zapRef to use in the cleanup function
|
||||||
|
const currentZapRef = zapRef.current;
|
||||||
|
|
||||||
// Create a new <script> element
|
// Create a new <script> element
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
@ -45,15 +48,15 @@ const ZapThreadsWrapper = ({ anchor, user, relays, disable, className, isAuthori
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Remove any existing <zap-threads> element
|
// Remove any existing <zap-threads> element
|
||||||
if (zapRef.current) {
|
if (currentZapRef) {
|
||||||
while (zapRef.current.firstChild) {
|
while (currentZapRef.firstChild) {
|
||||||
zapRef.current.removeChild(zapRef.current.firstChild);
|
currentZapRef.removeChild(currentZapRef.firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Append the new element
|
// Append the new element
|
||||||
if (zapRef.current) {
|
if (currentZapRef) {
|
||||||
zapRef.current.appendChild(zapElement);
|
currentZapRef.appendChild(zapElement);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -68,9 +71,9 @@ const ZapThreadsWrapper = ({ anchor, user, relays, disable, className, isAuthori
|
|||||||
|
|
||||||
// Cleanup function to remove the <zap-threads> element and the <script> element when the component is unmounted
|
// Cleanup function to remove the <zap-threads> element and the <script> element when the component is unmounted
|
||||||
return () => {
|
return () => {
|
||||||
if (zapRef.current) {
|
if (currentZapRef) {
|
||||||
while (zapRef.current.firstChild) {
|
while (currentZapRef.firstChild) {
|
||||||
zapRef.current.removeChild(zapRef.current.firstChild);
|
currentZapRef.removeChild(currentZapRef.firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Remove the <script> element from the <body> of the document
|
// Remove the <script> element from the <body> of the document
|
||||||
|
Loading…
x
Reference in New Issue
Block a user