Course contentsShow
← React
Lesson 278 of 2,3968. Props PatternsFree lesson

Passing Multiple Arguments to Render Props

Providing multiple values from the component to the render function for flexible consumer control.

Passing Multiple Arguments to Render Props

What you'll learn: How to give a render prop function access to multiple pieces of data at once for maximum flexibility.

So far you've seen render props receive a single argument—but what if your component needs to share more than one value? The solution is simple: just pass additional arguments to the function call.

The Core Idea

When you call the render prop function, you can pass as many arguments as you want, just like any function call. The consumer then receives all those values and decides which ones to use.

function DataProvider({ render }) {
  const user = { name: 'Alice', age: 28 };
  const loading = false;
  const error = null;

  return render(user, loading, error);
}

// Usage
<DataProvider 
  render={(user, loading, error) => {
    if (loading) return <p>Loading...</p>;
    if (error) return <p>Error!</p>;
    return <h1>Hello, {user.name}</h1>;
  }}
/>

Why Multiple Arguments?

Think of it like ordering at a restaurant: instead of just handing you a plate (single value), the waiter gives you your meal, utensils, and condiments (multiple values). You choose what to use.

This pattern shines when your component manages several related pieces of state or data. Rather than cramming everything into one object, you can expose each value separately, making the consumer's code cleaner and the intent clearer.

function MouseTracker({ children }) {
  const x = 120;
  const y = 45;
  const isMoving = true;

  return children(x, y, isMoving);
}

Key Takeaway: Pass multiple arguments to your render prop function just like any function call—this gives consumers precise control over which values they use without bundling everything into a single object.