DEV Community

Priyadarshini Sharma
Priyadarshini Sharma

Posted on

Day 1 of 7 โ€“ Learnings from โ€œLearn React with TypeScript โ€ by Carl Rippon.

๐˜๐จ๐ฎโ€™๐ฏ๐ž ๐ฉ๐ซ๐จ๐›๐š๐›๐ฅ๐ฒ ๐›๐ฎ๐ข๐ฅ๐ญ ๐ญ๐จ๐ง๐ฌ ๐จ๐Ÿ ๐‘๐ž๐š๐œ๐ญ ๐œ๐จ๐ฆ๐ฉ๐จ๐ง๐ž๐ง๐ญ๐ฌ.
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)