Ashish Kumar’s Post

View profile for Ashish Kumar, graphic

Frontend Developer | React, JavaScript, TypeScript & Next.js | Scalable Web App Architect | UX/UI Innovator at Rakuten India

Lately, I’ve been leveraging the Render Props pattern in React across both work and side projects, and it’s been incredibly effective! This pattern is a powerful way to create reusable components and share logic. For instance, imagine a situation where a component on a page needs some dynamic or stateful data. If this state is managed at the page level, every update could trigger a full-page re-render—something we’d want to avoid. Render Props provide a clean solution by isolating state management within the component itself, keeping the rest of the page unaffected. Here’s a simple counter example: #react #reactjs #typescript #javascript

  • react code for render props, example of render props
Ashish Kumar

Frontend Developer | React, JavaScript, TypeScript & Next.js | Scalable Web App Architect | UX/UI Innovator at Rakuten India

2w
Like
Reply
Ashish Kumar

Frontend Developer | React, JavaScript, TypeScript & Next.js | Scalable Web App Architect | UX/UI Innovator at Rakuten India

1w
Like
Reply
Benjamin Baron

software developer with project management experience

2w

Am curious, does it only work this way with the JSX getting generated by the arrow function or is it also possible to define the render props in Counter but the children can be nested inside Counter like: <Counter ...> <Children /> </Counter> ?

Like
Reply
Ferdian Satria Akbar

Frontend Developer | Backend Developer | Fullstack Developer

2w

It's very good, and in some situations, I often use it. However, it can be quite challenging to maintain when working with a team. In certain cases, some persons use patterns like this in components with very complex logic, making it hard to read. The worst-case scenario is when multiple hooks are used inside this, leading to a heavy rendering process. Nevertheless, I think this is a very cool code pattern if it's not overused.😎 Thanks for sharing Ashish Kumar 🙏

Slava Knyazev

Senior Software Developer | Blogging @ bbss.dev | Previously Amazon, Airbnb

2w

Rough idea, but you could also do this with contextual elements. You get a bit more composability out of it this way.

  • No alternative text description for this image
Mohit Kumar Toshniwal

Frontend Engineer | 12K@Linkedin | React.js | Next.js | JavaScript | Node.js | Vue.js | Three.js | R3F | WebXR | AR/VR

2w

I tend to use render props nowadays whenever I need to have a specific markup.

Emre Yurtseven

Informatiker (Computer Scientist, 2.3 ⌀)

2w

What about signals?

Like
Reply
Imran Shaikh

Full Stack & Blockchain Developer | Typescript | Rust 🦀

2w

Yeah, Render Props pattern could be handy in some situations. However, personally, I'm not a big fan of it because it can lead to messy or unreadable code if not used carefully. To be honest, having logic inside markup doesn't look good to me.

Tejas Chandrashekar

Frontend Engineer | Exploring the ReactJS ecosystem and JavaScript universe

2w

But doesn't the component passed to the render prop re-render all the time, because you are effectively passing a new object each time ?

Like
Reply
Alexandru Bereghici

Senior Frontend Developer

2w

I prefer custom hooks.

See more comments

To view or add a comment, sign in

Explore topics