简单React
0 1

请解释:React的Consumer组件?它有什么作用 是什么?

【概念释义】

Consumer 是 React Context 的旧式消费 API,<MyContext.Consumer>{value => ...}</MyContext.Consumer> 函数子节点接收 context 值。React 16.8+ 推荐 useContext(MyContext),Consumer 仍可用于 class 组件或避免 hook 规则场景。

【基础使用】

jsx
const ThemeContext = createContext('light');

function ThemedButton() {
  return (

登录查看完整 1211

回答讨论

暂无讨论,登录后可抢先发言

本题库更多题目(50)