next-client-utils
🧩 Utilities to bridge server and client components seamlessly in Next.js apps.
✨ Features
- 🖱️ Interactive popups: Trigger popups on click or hover for any element.
- ⚛️ SSR-friendly: Keep elements server-side rendered while using
WithPopup
.
- 🌐 Server-side popup rendering: Dynamically generate popup content via
renderSSRPopUp
.
- 🎯 Customizable positioning: Fine-tune popup placement using flexible props.
- 🪝 Essential React hooks: Includes
useOutsideClick
, useElementPositionChange
, and more.
- 🌀 Debounce utility: Built-in and fully customizable debounce mechanism.
- 🧱 Column listing UI pattern: Automatically animates updated rows to the top—ideal for chat or feed-style interfaces.
- ⚡ Next.js-ready: Works out of the box with Server and Client Components.
🔍 What does it look like?
import { WithPopup } from 'next-client-utils';
export default function ServerComponent() {
return (
<WithPopup
PopUp={PopUp}
popupProps={{}} // Pass `{}` if your popup is typed as React.FC<{}>
triggerType="hover" // Optional, defaults to "click"
>
<div>Open PopUp</div>
</WithPopup>
);
}
'use client';
type PopUpProp={
close?: () => void
}
const PopUp: React.FC<PopUpProp> = (props) => {
return <div><p>This is PopUp</p>
<button onClick={props.close?.()}>Close</button>
</div>;
};
🔍 Another Example?
import { WithPopup } from 'next-client-utils';
export default function ServerComponent() {
return (
<WithPopup
PopUp={ProfileDetailPopUp}
popupProps={{
firstName: "Prateek",
lastName: "Sharma",
}}
gap={15} // Optional spacing between trigger and popup
childrenWrapperComponent={UserName}
>
<>SSR Text</>
</WithPopup>
);
}
'use client';
type ProfileDetailPopUpProps = {
firstName: string;
lastName: string;
};
const ProfileDetailPopUp: React.FC<ProfileDetailPopUpProps> = ({ firstName, lastName }) => {
return <div>This is PopUp</div>;
};
type UserNameProps = {
isPopUpActive: boolean;
children: React.ReactNode;
};
const UserName: React.FC<UserNameProps> = ({ isPopUpActive, children }) => {
return <div>{children}</div>;
};
import {WithPopup} from 'next-client-utils';
export default function ServerComponent(props: any) {
const renderSSRPopUp = async (popupProps: any) => {
'use server';
return <AnotherServerComponent {...popupProps} />;
};
return (
<WithPopup
renderSSRPopUp={renderSSRPopUp}
popupProps={props} // Pass required props here
triggerType="hover" // Optional
>
<div>Open PopUp</div>
</WithPopup>
);
}
export default function AnotherServerComponent(props: any) {
return <div>This PopUp is server-rendered</div>;
}
npm install next-client-utils
yarn add next-client-utils
🤝 Support
If you face any issues during integration or come across a bug, feel free to reach out to me on LinkedIn — happy to help!