我有一个父组件,充当其子组件的包装器。如何将道具传递给将使用以下格式渲染的子项?
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>);
临摹微笑
相关分类