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

replace toaster with new useToaster api #1351

Merged
merged 19 commits into from
Jun 14, 2023
Merged

replace toaster with new useToaster api #1351

merged 19 commits into from
Jun 14, 2023

Conversation

mayank99
Copy link
Contributor

@mayank99 mayank99 commented Jun 12, 2023

Changes

The Toaster class instance been replaced with a useToaster hook which returns an object that has properties matching the public functions in the old api.

Only api change needed from user side is:

- import { toaster } from '@itwin/itwinui-react';
+ import { useToaster } from '@itwin/itwinui-react';

  export default () => {
+   const toaster = useToaster();

    return <button onClick={() => toaster.positive('hello')}>show</button>
  };

How it works

  • The useToaster hook simply dispatches reducer actions.
  • The reducer state is stored in <ToastProvider>, which wraps the entire tree inside <ThemeProvider>.
  • <ThemeProvider> renders a <Toaster> which reads the state and renders <Toast>s accordingly.

TODO: Will work on unit tests Fixed.

Testing

Tested in vite playground and storybook.

Everything seems to work well. 🎉

Docs

Added changeset.

Need to fix website example. Fixed via #1353.

Updated migration guide. https://github.com/iTwin/iTwinUI/wiki/iTwinUI-react-v3-migration-guide#toaster

@mayank99 mayank99 added this to the React 3.0 milestone Jun 12, 2023
@mayank99 mayank99 self-assigned this Jun 12, 2023
@mayank99 mayank99 requested review from a team as code owners June 12, 2023 20:36
@mayank99 mayank99 requested review from gretanausedaite and adamhock and removed request for a team June 12, 2023 20:36
@mayank99 mayank99 mentioned this pull request Jun 12, 2023
24 tasks
@mayank99 mayank99 changed the base branch from dev to mayank/themeprovider-examples June 13, 2023 19:42
@mayank99 mayank99 changed the title new useToaster api replace toaster with new useToaster api Jun 13, 2023
@mayank99 mayank99 force-pushed the mayank/use-toaster branch from 00207e0 to 2457974 Compare June 13, 2023 21:36
Copy link
Contributor

@gretanausedaite gretanausedaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple questions. Other than that component looks much simpler!

packages/itwinui-react/src/core/Toast/Toaster.tsx Outdated Show resolved Hide resolved
packages/itwinui-react/src/core/Toast/Toaster.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@gretanausedaite gretanausedaite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Base automatically changed from mayank/themeprovider-examples to dev June 14, 2023 14:04
@mayank99 mayank99 merged commit 203c5b5 into dev Jun 14, 2023
@mayank99 mayank99 deleted the mayank/use-toaster branch June 14, 2023 14:28
@imodeljs-admin imodeljs-admin mentioned this pull request Oct 23, 2023
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