Skip to content

Commit

Permalink
fix(notice): fix limit 1 on useNotice does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
108yen committed Feb 6, 2024
1 parent f90795f commit 6b9dc0a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/swift-rice-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@yamada-ui/notice": patch
---

fix limit 1 on useNotice does not work
10 changes: 7 additions & 3 deletions packages/components/notice/src/notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,16 +220,20 @@ const createNoticeStore = (initialState: State): Store => {
},

create: (message, options) => {
const limit = (options.limit ?? 0) - 1
const limit = options.limit

const notice = createNotice(message, options)
const { placement, id } = notice

setState((prev) => {
let prevNotices = prev[placement] ?? []

if (limit > 0 && prevNotices.length > limit) {
const n = prevNotices.length - limit
if (
limit !== undefined &&
limit > 0 &&
prevNotices.length > limit - 1
) {
const n = prevNotices.length - (limit - 1)
const notices = placement.includes("top")
? prevNotices.slice(n * -1)
: prevNotices.slice(0, n)
Expand Down

0 comments on commit 6b9dc0a

Please sign in to comment.