Reactjs 有没有办法检查道具功能并将其传递到下一级
嗨,我正在尝试将一个函数传递给容器树。假设我在a中定义一个函数,将它传递给B,然后从B传递给C。现在我想在B中做一个检查,如果我传递那个函数,如果是,我向下传递它。有什么办法吗 以下是B函数:Reactjs 有没有办法检查道具功能并将其传递到下一级,reactjs,Reactjs,嗨,我正在尝试将一个函数传递给容器树。假设我在a中定义一个函数,将它传递给B,然后从B传递给C。现在我想在B中做一个检查,如果我传递那个函数,如果是,我向下传递它。有什么办法吗 以下是B函数: function CategoriesTable({ data, deleteContent }) { return ( <> <Table responsive> <thead> <tr>
function CategoriesTable({ data, deleteContent }) {
return (
<>
<Table responsive>
<thead>
<tr>
<th>Category Name</th>
<th className='text-center'>Count</th>
<th className='actions'></th>
</tr>
</thead>
<tbody>
{data.map((category) => (
<CategoriesTableRow
category={category}
deleteContent={(id) => deleteContent(id)}
/>
))}
</tbody>
</Table>
</>
);
}
函数可分类({data,deleteContent}){
返回(
类别名称
计数
{data.map((类别)=>(
deleteContent(id)}
/>
))}
);
}
现在我想验证我是否得到一个delete函数?如何执行此操作?您可以在调用函数之前检查函数
deleteContent={(id) => deleteContent && deleteContent(id)}
或设置默认参数
function CategoriesTable({ data, deleteContent = () => null })
您可以在调用函数之前检查它
deleteContent={(id) => deleteContent && deleteContent(id)}
或设置默认参数
function CategoriesTable({ data, deleteContent = () => null })
嗨,你可以这样检查
function CategoriesTable({ data, deleteContent = () => null }) {
console.log("Am i getting the function",deleteContent); //to check only by printing it on console
return (
<>
<Table responsive>
<thead>
<tr>
<th>Category Name</th>
<th className='text-center'>Count</th>
<th className='actions'></th>
</tr>
</thead>
<tbody>
{data.map((category) => (
<CategoriesTableRow
category={category}
deleteContent={(id) => deleteContent && deleteContent(id)}
/>
))}
</tbody>
</Table>
</>
);
}
函数CategoriesTable({data,deleteContent=()=>null}){
log(“我正在获取函数”,deleteContent);//仅通过在控制台上打印来检查
返回(
类别名称
计数
{data.map((类别)=>(
deleteContent&&deleteContent(id)}
/>
))}
);
}
您好,您可以这样检查
function CategoriesTable({ data, deleteContent = () => null }) {
console.log("Am i getting the function",deleteContent); //to check only by printing it on console
return (
<>
<Table responsive>
<thead>
<tr>
<th>Category Name</th>
<th className='text-center'>Count</th>
<th className='actions'></th>
</tr>
</thead>
<tbody>
{data.map((category) => (
<CategoriesTableRow
category={category}
deleteContent={(id) => deleteContent && deleteContent(id)}
/>
))}
</tbody>
</Table>
</>
);
}
函数CategoriesTable({data,deleteContent=()=>null}){
log(“我正在获取函数”,deleteContent);//仅通过在控制台上打印来检查
返回(
类别名称
计数
{data.map((类别)=>(
deleteContent&&deleteContent(id)}
/>
))}
);
}