Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destroying the instance does not unmount the component #46

Open
pqnet opened this issue Jan 30, 2024 · 0 comments
Open

Destroying the instance does not unmount the component #46

pqnet opened this issue Jan 30, 2024 · 0 comments

Comments

@pqnet
Copy link

pqnet commented Jan 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant