๐๐จ๐ฎโ๐ฏ๐ ๐ฉ๐ซ๐จ๐๐๐๐ฅ๐ฒ ๐๐ฎ๐ข๐ฅ๐ญ ๐ญ๐จ๐ง๐ฌ ๐จ๐ ๐๐๐๐๐ญ ๐๐จ๐ฆ๐ฉ๐จ๐ง๐๐ง๐ญ๐ฌ.
But how many are reusable across different parts of your app?
๐๐ฆ๐ตโ๐ด ๐ต๐ข๐ญ๐ฌ ๐ข๐ฃ๐ฐ๐ถ๐ต ๐ฐ๐ฏ๐ฆ ๐ต๐ฉ๐ข๐ต ๐ด๐ฐ๐ถ๐ฏ๐ฅ๐ด ๐ด๐ช๐ฎ๐ฑ๐ญ๐ฆโฆ ๐ฃ๐ถ๐ต ๐ช๐ด๐ฏโ๐ต: ๐ต๐ฉ๐ฆ
<๐๐ฅ๐๐ซ๐ญ /> ๐๐จ๐ฆ๐ฉ๐จ๐ง๐๐ง๐ญ ๐
๐๐ง ๐๐ฅ๐๐ซ๐ญ ๐ฌ๐ก๐จ๐ฎ๐ฅ๐ ๐๐ ๐๐๐ฌ๐ฒ, ๐ซ๐ข๐ ๐ก๐ญ?
Just show a message, maybe a color, maybe a close button.
But then someone asks:
๐๐ข๐ฏ ๐ช๐ต ๐ฃ๐ฆ ๐ฅ๐ช๐ด๐ฎ๐ช๐ด๐ด๐ช๐ฃ๐ญ๐ฆ?
๐๐ข๐ฏ ๐ธ๐ฆ ๐ค๐ถ๐ด๐ต๐ฐ๐ฎ๐ช๐ป๐ฆ ๐ต๐ฉ๐ฆ ๐ฉ๐ฆ๐ข๐ฅ๐ช๐ฏ๐จ?
๐๐ข๐ฏ ๐ธ๐ฆ ๐ฌ๐ฏ๐ฐ๐ธ ๐ธ๐ฉ๐ฆ๐ฏ ๐ช๐ต ๐จ๐ฆ๐ต๐ด ๐ค๐ญ๐ฐ๐ด๐ฆ๐ฅ?
Now youโre juggling logic, props, and state
โชPriya Sharmaโฌ
โช@priya1.bsky.socialโฌ
ยท 12d
Hereโs a solid pattern that makes your components actually reusable (not just copy-pasteable):
๐น๐๐ซ๐จ๐ฉ๐ฌ โ control content & behavior
๐๐๐ญ๐๐ญ๐ โ manage interaction
๐ฃ๐๐ฏ๐๐ง๐ญ๐ฌ โ notify parent components
Letโs break it down โ
Start with a clear contract using TypeScript:
type AlertProps = {
heading: string;
type: 'info' | 'error';
closable?: boolean;
onClose?: () => void;
};
Make it interactive:
const [visible, setVisible] = useState(true);
if (!visible) return null;
Let it talk to the parent too:
const handleClose = () => {
setVisible(false);
if (onClose) onClose();
};
Reusable components arenโt just about splitting up the UI.
Theyโre about creating building blocks that can scale with your app.
React + TypeScript gives you all the tools, you just need the right pattern - https://www.amazon.com/Learn-React-TypeScript-real-world-production-ready/dp/1836643179/****
Top comments (0)