reacord icon indicating copy to clipboard operation
reacord copied to clipboard

Destroying the instance does not unmount the component

Open pqnet opened this issue 1 year ago • 0 comments

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

pqnet avatar Jan 30 '24 00:01 pqnet