I'm following this question to learn how to pass props to children. I'm getting an error in my own components, though.
Component 1, DataWrapper:
export default function DataWrapper(props) {
return (
<DashboardWrapper>
{cloneElement(props.children, { test: "hello there" })}
</DashboardWrapper>
);
}
Component 2, Migration:
export default function Migration(props) {
console.log("props.test");
console.log(props.test);
return (
<DataWrapper>
<div>hello</div>
</DataWrapper>
);
}
I'm trying to pass the test
prop from DataWrapper
to Migration
. However, I'm getting undefined
when running console.log(props.test);
. Am I passing the test
prop incorrectly? What must I do to successfully pass props to children?