I have a component named EditForm which I imported in another component called ProductList. I need to pass EditForm component from ProductList to another component ListContainer as props and render it (EditForm) inside ListContainer. The flow is given below for better understanding:
// EditForm.js
const EditForm = () => {...}
export default EditForm
// ProductList.js
import EditForm from "./EditForm"
..
<ListContainer editForm={EditForm} /> // pass the editform as props
// ListContainer.js
const ListContainer({editForm: EditForm}) => {
...
<EditForm /> // use editform here
}
Here is my code below:
ProductList.js
import React from "react"
import ListContainer from "../common/ListContainer";
import EditForm from "./EditForm";
const ef = () => {
return (<EditForm />)
}
const ProductList = () => {
return (
<React.Fragment>
<ListContainer ef={ef} />
</React.Fragment >
)
}
export default ProductList
ListContainer.js
import React, { useState } from "react"
const ListContainer = ({ ef: EditComponent }) => {
return (
<React.Fragment>
<EditComponent />
</React.Fragment >
)
}
export default ListContainer
FULL CODE LINK: https://onecompiler.com/javascript/3yfvnyyf4
