I have a Layout component as follows:
import React, { useRef, useEffect, useState } from "react"
import Navbar from "./Navbar"
import "../styles/mains.scss"
const Layout = ({ children }) => {
return (
<>
<Navbar></Navbar>
<main>
{children}
</main>
</>
)
}
export default Layout
I use Layout with some nested children in my Home component among other places:
import React from "react";
import Layout from "./layout";
import Header from "./Header";
import Work from "./Work";
import About from "./about";
import Footer from "./Footer";
export const Home = () => {
return (
<Layout>
<Header/>
<Work/>
<About/>
<Footer/>
</Layout>
);
};
I now have a requirement that I pass props down into specific children. Specifically I need to pass a function into my child Work component. But I have no idea how to parse through the children and conditionally pass a function to a specific child component if it exists. Note that in many cases the Layout will not have the Work component as a child.