reacord
reacord copied to clipboard
Destroying the instance does not unmount the component
Invoking instance.destroy()
does not unmount the component. As a consequence configured effects are not cleaned up.
This can be seen using the two components from the guide, Uptime
and SelfDestruct
in the same message.
function Uptime() {
const [startTime] = useState(Date.now())
const [currentTime, setCurrentTime] = useState(Date.now())
useEffect(() => {
const interval = setInterval(() => {
setCurrentTime(Date.now())
}, 3000)
return () => clearInterval(interval)
}, [])
return <>this message has been shown for {currentTime - startTime}ms</>
}
export function SelfDestruct() {
const instance = useInstance()
return (
<Button
style="danger"
label="delete this"
onClick={() => instance.destroy()}
/>
)
}
reacord.createChannelMessage(channel).render(<><Uptime /><SelfDestruct /></>)
After the "self destruct" button is clicked the interval trigger keeps on going, repeatedly printing this message in console:
Attempted to update a deactivated message
Tested with React 18.2.0, reacord 0.6.0, and discord.js 14.14.1