-我正在使用功能组件。- 现在我在这里使用 3 个组件,其中一个是父组件,另外 2 个是子组件。- 我需要访问一个子组件方法或状态到另一个子方法。我已经使用CreateRef完成了类组件,但现在我需要使用函数组件,但我在“ref.current”中得到 Null。
export function SideBySideList(props) {
const ref = React.createRef();
//this is call inside ListPage after sucess
function updateRightList(id) {
ref.current.state.actualSearchedModel.Id = id
ref.current.fetchDataAndUpdate();
}
function itemClicked(id) {
updateRightList(id);
}
return (
<>
<div className="col-12 no-padding">
<div className={props.leftListLayoutClass}>
<ListPage
updateRightList={updateRightList}
/>
</div>
<div className={props.rightListLayoutClass}>
<ListPage
ref={ref}
/>
</div>
</div>
<>
);
}Run Code Online (Sandbox Code Playgroud)