From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Function as children pattern

Function as children pattern

In this lecture, we'll explore another React pattern called the function-as-children pattern, also known as children-as-a-function. Normally in React, when you pass something between opening and closing tags of a component, that's just JSX children. Alright, let's talk about the function-as-children pattern. With this pattern, instead of passing JSX, you actually pass a function as the child. That function doesn't just sit there. The parent component will call it, and when it does, it provides some data, or state, as arguments. The function then returns React elements that can use that data however it likes. The beauty of this pattern is flexibility. The parent is responsible for all the logic, like fetching data or managing state, and the child decides exactly how that data should be displayed. So we get a really clean separation of concerns – logic in one place, UI in another. In this example, data provider might fetch some data. Instead of deciding how to render it, it simply…

Contents