Skip to content

Commit

Permalink
feat: throw an error if animated-subscribe-button don't receive two <…
Browse files Browse the repository at this point in the history
…span> elements
  • Loading branch information
itsarghyadas committed Jan 14, 2025
1 parent 22102de commit 337655f
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions registry/default/magicui/animated-subscribe-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ export const AnimatedSubscribeButton = React.forwardRef<
) => {
const [isSubscribed, setIsSubscribed] = useState<boolean>(subscribeStatus);

if (
React.Children.count(children) !== 2 ||
!React.Children.toArray(children).every(
(child) => React.isValidElement(child) && child.type === "span",
)
) {
throw new Error(
"AnimatedSubscribeButton expects two children, both of which must be <span> elements.",
);
}

const childrenArray = React.Children.toArray(children);
const initialChild = childrenArray[0];
const changeChild = childrenArray[1];
Expand Down

0 comments on commit 337655f

Please sign in to comment.