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

Fix undefined id #35

Merged
merged 1 commit into from
Feb 19, 2021
Merged

Fix undefined id #35

merged 1 commit into from
Feb 19, 2021

Conversation

hudochenkov
Copy link
Contributor

I have a custom toast function which adds features to toast I need on a project. Simplified example:

function customToast({ id ...props }) {
	return toast(
		(t) => (
			<CustomToast {...props} />
		),
		{
			id,
		},
	);
}

I works same as original toast — returns id to allow updating existing toast, or dismiss it.

const id = customToast({ message: 'hey' }); //

customToast({ id, message: 'hi' };

However, in this example id is undefined. There is a fallback to genId(), but it gets overridden by ...opts.

What happens is id: opts?.id || genId() receives undefined and sets fallback, but then ...opts set id back to undefined.

@vercel
Copy link

vercel bot commented Feb 2, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/timo/react-hot-toast/6sxfgf8t5
✅ Preview: https://react-hot-toast-git-fork-hudochenkov-fix-id.timo1.vercel.app

@timolins timolins merged commit 8cd1535 into timolins:main Feb 19, 2021
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

Successfully merging this pull request may close these issues.

2 participants