code-forge-io / code-forge-io/remix-toast

Toast not working properly

Open
#13 11 comments 3 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
262
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Hi I followed the initial steps to get the toast going with sonner see below, but it is not working.
Expected behaviour:
Toast to work when being called.

What is happening:
Toast gets called on refresh twice, and doesn't get cleared, if I refresh it continues to get called.

Is something else missing?

from route
```
// ... imports

export const action = async ({ request }: ActionFunctionArgs) => {
return jsonWithError(null, 'There are errors in the form')
}
```

from root
```
// ... imports

export const loader = async ({ request }: LoaderFunctionArgs) => {
// ... otherHeaders logic
const { toast, headers: toastHeaders } = await getToast(request)

return json(
{
toast
},
{
headers: {
// ...otherHeaders,
...toastHeaders
}
}
)
}

export default function Home() {
const { toast: serverToast } = useLoaderData()

useEffect(() => {
console.log('serverToast', serverToast)

if (serverToast?.type === 'success') {
toast.success(serverToast.message)
}
if (serverToast?.type === 'error') {
toast.error(serverToast.message)
}
}, [serverToast])

return (



Basic Example With Remix Toast



{children}





)
}
```

using
```
devDeps
@remix-run/dev -> 2.8.1
@remix-run/eslint-config -> 2.8.1

deps
@remix-run/serve -> 2.8.1
@remix-run/react -> 2.8.1
@remix-run/node -> 2.8.1
sonner -> 1.4.0
```

Edit: Just wanted to say congrats with the lib though, fantastic explanation on the blog.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.