s2ui
Version:
A UI library by s2sharpit.
18 lines (15 loc) • 575 B
JavaScript
'use client'
import * as React from 'react';
import { useCallback } from 'react';
const Scroll = React.forwardRef(({ className, children, to, ...props }, ref) => {
const handleClick = useCallback((e) => {
e.preventDefault();
const element = document.getElementById(to);
if (element) {
element.scrollIntoView({ behavior: "smooth" });
}
}, [to]);
return (React.createElement("button", { ...props, ref: ref, onClick: handleClick, className: className }, children));
});
Scroll.displayName = "Scroll";
export { Scroll };