M
M
Maxim Korolsky2017-01-05 19:37:58
React
Maxim Korolsky, 2017-01-05 19:37:58

Is there a way to pass all props to the children element?

children = React.cloneElement(this.props.children, {
        fetchLatestPosts: this.props.fetchLatestPosts,
        latestPosts: this.props.latestPosts,
        childPath: this.props.childPath,
        onChangePage: this.props.onChangePage,
      })

Now I do it like this
I would like something like this
children = React.cloneElement(this.props.children, this.props)

But if I do this - Maximum callstack size

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
abberati, 2017-01-16
@SuperPosan

const props = {
  children: 'example JSX element',
  className: 'pirozhok',
  someProp: 42
}

const newProps = Object.assign({}, props);
delete newProps.children;

const children = React.cloneElement(props.children, newProps)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question