cloneElement is not working properly
See original GitHub issuecloneElement 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:
- Created 6 years ago
- Comments:11 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@developit ah I figured this out. It’s actually the lack of support for synthetic events that was the issue.
@prateekbh
cloneElement
only works on single elements, and thechildren
prop is always of type array. In your case you likely don’t needcloneElement
at all.I just compared our implementation with react’s and we both do the same thing, minus the difference with
synthetic events
.