Skip to content

[Docs] Add Example For React.Children.map  #2027

Description

@adeelibr

For https://reactjs.org/docs/react-api.html#reactchildrenmap to help illustrate as to what it does, can we kindly add an example for something like this.

const Value = ({ value }) => <p>{value}</p>

const PropsInjector = ({ children }) => React.Children.map(children, child => {
  return React.cloneElement(child, { value: 'some_value'  });
});

const App = () => (
   <PropsInjector>
        <Value />
        <Value />
    </PropsInjector>
)

I don't know if this might be an acceptable example for React.Children.map, but I would love to hear some feedback if possible.

The current documentation doesn't have a an example on how React.Children.map can be used & it doesn't make sense for someone like me

As per docs: React.Children.map(children, function[(thisArg)])

For someone like me I got very confused function[(thisArg)] when I read this & didn't know on how I could use it.

I am more then happy to make a PR for adding this example & or any better example if someone can suggest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions