What is the React.Children API?
Answer
React.Children provides utility functions for working with props.children, which can be a single element, array, string, or undefined — making it tricky to work with directly. React.Children.map(children, fn): like Array.map but handles all child types (including null/undefined); returns a new array of React elements. React.Children.forEach(children, fn): same but returns nothing (for side effects). React.Children.count(children): returns the number of children. React.Children.only(children): returns the single child or throws if not exactly one child — useful for enforcing that a component accepts exactly one child. React.Children.toArray(children): flattens and converts to a real array with stable keys. Limitations: React.Children is deprecated in favor of modern patterns (direct array methods on children, or React 19's improvements). Issues include that cloning elements via React.Children.map can cause key warnings and is fragile. Modern alternative: if children is always an array (e.g., enforced by TypeScript), you can use Array.isArray checks and work directly.