I am having a hard time understanding the behaviour of React.cloneElement() function
I have my Component Structure something like this
A.js
export default class A extends React.Component {
render() {
return (<h1>{ this.props.message }</h1>)
}
}
B.js
import A from "./A"
const newComponent = React.cloneElement(A,{
message: "Hello World"
})
export default newComponent
C.js
import B from "./B"
import { BrowserRouter as Router, Route } from "react-router-dom"
// To Be very precise
export default class C extends React.Component {
render() {
return (
<Router>
<Route path="/" component={B} />
</Router>
)
}
}
But I get this Error
Invalid prop component of type object supplied to Route, expected function.
but When I pass Component A directly into the Route component, it renders fine.
When I console.log Component A inside the render function of Component C, I get a function but
When I console.log Component B inside the render function of Component C, I get a object
What am I missing?
cloneElement?Component BtoComponent A... say it somewhat requirement of my project.HOCfor this purposeComponent Ba HOCCloneElementdo exactly? I have seen examples of using the function to clonechildrenof React Components. @SaeidAlidadi