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

Re-render children when add toast #100

Open
ngvcanh opened this issue Mar 1, 2023 · 0 comments
Open

Re-render children when add toast #100

ngvcanh opened this issue Mar 1, 2023 · 0 comments

Comments

@ngvcanh
Copy link

ngvcanh commented Mar 1, 2023

This package has issues:

  • Re-render all app when add new a toast
  • Support children for React 18

Re-render all app when add new a toast

In ToastProvider, you make state:

const [toasts, setToasts] = React.useState<FullToastConfig[]>([]) // line 49

And when has a new toast, this state will be update, ToastProvider re-render, that mean children also re-render. This is an error of performance.

Should make the component as children of ToastProvider (Ex: ToastContainer) manage toasts state. This component is ForwardRefExoticComponent.

When add toast, let call add function from ref of ToastContainer

Support children for React 18

In Context.tsx, I suggest code:

const ToastProvider: React.FC<Omit<ToastContextType, 'toast'>> = ({

change to:

export type ToastProviderProps = Omit<ToastContextType, 'toast'>;
const ToastProvider: React.FC<PropsWithChildren<ToastProviderProps >> = ({
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