我在SomeCompoent中有一个公共方法。如何在其父母处调用它?
const firstDateComponent = ({ month, year, navigate }) => {
const firstDate = new Date(year, month, 1).getDay();
function getEmptyDays(firstDate) {
const emptyDays = [];
for(let i=0; i < firstDate; i++) {
emptyDays.push(
<li className='month-day empty' key={ `${year}${month}-empty${i}`}>.</li>
);
}
return emptyDays;
}
if(navigate){
//call the clear method here
}
return (
<div>
<ul className='months'>
<SomeCompoent ref={param => this.__selection = param}>
{ getEmptyDays(firstDate) }
</SomeCompoent>
</ul>
<p onClick={e => this.__selection.clear()}>this work if call in jxs</p>
</div>
);
}
我设法通过使用ref在jsx中调用clear方法。但是如何在nagivate if语句中调用呢?