Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get deep children #3

Closed
einarq opened this issue Nov 15, 2017 · 5 comments
Closed

How to get deep children #3

einarq opened this issue Nov 15, 2017 · 5 comments
Labels

Comments

@einarq
Copy link

einarq commented Nov 15, 2017

Is this meant to be used when testing? Can't otherwise see how to get children recursively, at least children is not deep in my experiments.

@fernandopasik
Copy link
Owner

You could use it for testing, but seems more logical that in tests you will compare two snapshots of a component

@einarq
Copy link
Author

einarq commented Nov 15, 2017 via email

@fernandopasik
Copy link
Owner

Sure

if you have the following element:

const List = () => (
  <ul>
    <li>First</li>
    <li>Second</li>
    <li>Third</li>
  </ul>
);

And you have another element like:

const TitlesList = (props) => {
  const children = Children.deepMap(props.children,
          child => (
            child.type === 'li'
              ? cloneElement(child, { ...child.props, className: 'title' })
              : child
          ),
        );
  return (
    <div className="titles-list">
        {children}
    </div>
  );
};

And they are used like:

<TitlesList>
   <List/>
</TitlesList>

@fernandopasik
Copy link
Owner

What are you trying to accomplish that you need from the library?

@fernandopasik
Copy link
Owner

I think the library already supports what you are looking for. If further is needed I'll reopen this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants