I have a Parent component that acts as a wrapper to its children. How do I pass a prop to a child that will be rendered using the format below?
import React, { useEffect, useState } from 'react';
const Parent = ({ children }) => {
const [completeState, setCompleteState] = useState(false);
useEffect(
() => {
/* .. code that runs then sets completeState to true */
setCompleteState(true);
}, []
);
return (
<section>
/*
how to pass a 'didComplete' prop to children?
didComplete={completeState}
*/
{children} // Child component below would be rendered here with the didComplete prop passed in
</section>
)
}
import React from 'react';
const Child = ({ didComplete }) => (<h1>The function completed? {didComplete}</h1>);