question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cloneElement is not working properly

See original GitHub issue

cloneElement is not working for extended classes or stateless react components Both examples are working in React but only second is working in Preact.

working only in React

class Test extends Component {
}

cloneElement(Test, { param: 111});

working in both React and Preact

class Test extends Component {
}

cloneElement(<Test />, { param: 111});

I know that standard is to return <Test param={111} /> but this behaviour is inconsistent with react. Maybe it is related to preact-compat

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
paul-craciunoiu-ckcommented, May 25, 2017

@developit ah I figured this out. It’s actually the lack of support for synthetic events that was the issue.

0reactions
marvinhagemeistercommented, May 20, 2018

@prateekbh cloneElement only works on single elements, and the children prop is always of type array. In your case you likely don’t need cloneElement at all.

I just compared our implementation with react’s and we both do the same thing, minus the difference with synthetic events.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React cloneElement is not working for functional component
I would like to add some props to my component using {React.cloneElement(<MyComponent />, ...
Read more >
CloneElement not working as expected · Issue #4203 - GitHub
I have some code that lays out components like a XAML stack Panel that looks for layout properties and calculates the style based...
Read more >
Typescript(ing) React.cloneElement or how to type a child ...
cloneElement to create a new component which is received as a child (using props.chidren) and to pass to it a new prop. The...
Read more >
cloneElement - React Docs
cloneElement lets you create a new React element using another element as a starting point. ... Cloning an element does not modify the...
Read more >
Devon Govett on Twitter: "Starting to think that `React ...
If someone wraps the intended element with their own component, they have to ensure that the props you add with `cloneElement` are passed...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found