【发布时间】:2021-04-23 20:11:31
【问题描述】:
我正在尝试使用 TableContext 来检查子组件内的当前大小。但是,除了undefined,我很难得到任何东西:
const Bar = () => {
const tableContext = React.useContext(TableContext)
const tableContextLvl2 = React.useContext(Tablelvl2Context)
console.log(tableContext) // logs "undefined"
console.log(tableContextLvl2) // logs "undefined"
return <TableRow>
<TableCell>
hello
</TableCell>
</TableRow>
}
export const Foo = () => {
return (
<TableContainer>
<Table>
<TableBody>
<Bar />
</TableBody>
</Table>
</TableContainer>
)
}
我在这里缺少什么?查看source 时,看起来<Table> 为其子组件提供了一个上下文,因此期望得到一些东西。
我使用的是 Material-ui 版本 4.11.3。
【问题讨论】:
-
我看到这已经被问过了:stackoverflow.com/questions/66078662/…
标签: reactjs material-ui