近期為了熟悉元件 Component 的客製化,便參照「哎呀!不小心刻了一套 React UI 元件庫」一書進行練習。這篇筆記下 Toast 的實踐方法。
[ Repo ]:https://github.com/andy922200/practice-storybook-react
內容
1. Toast 是一種輕量級的訊息提示方式。預設是會在畫面頂部置中出現一個對話框,並會在一段時間後自動消失。
2. 透過 ReactDom.render() 方法,將目標的 Toast 元件渲染到指定的 <div> 上。因此,需要撰寫生成一個用來掛載 Toast 的 <div>,並在一段時間後將其移除。在 React 18 後,此方法必須改用 createRoot(<DOM位置>).render(<Render 的內容>)
3. 為了方便在 callback 中使用,新增了一個 message 方法,省去每次引入都得自行撰寫一個 Container 元件的困擾
參數
type – 提示訊息的種類
content – 提示訊息內容,一般是純文字
duration – 提示訊息時間,預設為 3 s
程式碼
相關文章
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 30 – 佈署發佈
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 30 – 佈署發佈 [筆記] 哎呀!不小心刻了一套 React UI 元件庫 30 – 佈署發佈](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 28 – Modal
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 28 – Modal [筆記] 哎呀!不小心刻了一套 React UI 元件庫 28 – Modal](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 27 – Progress Circle
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 27 – Progress Circle [筆記] 哎呀!不小心刻了一套 React UI 元件庫 27 – Progress Circle](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 26 – Progress Bar
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 26 – Progress Bar [筆記] 哎呀!不小心刻了一套 React UI 元件庫 26 – Progress Bar](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 25 – Skeleton
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 25 – Skeleton [筆記] 哎呀!不小心刻了一套 React UI 元件庫 25 – Skeleton](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 24 – Spin
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 24 – Spin [筆記] 哎呀!不小心刻了一套 React UI 元件庫 24 – Spin](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 23 – Pagination
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 23 – Pagination [筆記] 哎呀!不小心刻了一套 React UI 元件庫 23 – Pagination](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 22 – Tabs
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 22 – Tabs [筆記] 哎呀!不小心刻了一套 React UI 元件庫 22 – Tabs](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 21 – Drawer
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 21 – Drawer [筆記] 哎呀!不小心刻了一套 React UI 元件庫 21 – Drawer](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
★全文分享★ [筆記] 哎呀!不小心刻了一套 React UI 元件庫 20 – Select
![[筆記] 哎呀!不小心刻了一套 React UI 元件庫 20 – Select [筆記] 哎呀!不小心刻了一套 React UI 元件庫 20 – Select](https://smlpoints.com/wp-content/uploads/notes-react-hooks-ch1-ch2-1.jpeg)
近期為了熟悉元件 Component 的客製化,便
