简体   繁体   English

_react.default.useContext不是函数

[英]_react.default.useContext is not a function

  • I am using material ui stepper. 我正在使用材料ui步进器。
  • I used from there site but its broken 我从那里使用过网站,但它已经坏了
  • so I debugged and gave console inside VerticalLinearStepper method. 所以我调试并在VerticalLinearStepper方法中提供了控制台。
  • its printting a method at this line console.log("useStyles----->", useStyles); 它在此行console.log中打印一个方法(“useStyles ----->”,useStyles);
  • but I am facing an error _react.default.useContext is not a function 但我面临一个错误_react.default.useContext不是一个函数
  • can you tell me how to fix it. 你能告诉我如何解决它吗?
  • so that in future I will fix it myself. 所以将来我会自己修理它。
  • providing code snippet and sandbox below 在下面提供代码片段和沙箱

https://codesandbox.io/s/v3o3zmxk90 https://codesandbox.io/s/v3o3zmxk90

function VerticalLinearStepper() {
  console.log("useStyles----->", useStyles);

  const classes = useStyles();

  const [activeStep, setActiveStep] = React.useState(0);
  const steps = getSteps();

  function handleNext() {
    setActiveStep(prevActiveStep => prevActiveStep + 1);
  }

  function handleBack() {
    setActiveStep(prevActiveStep => prevActiveStep - 1);
  }

  function handleReset() {
    setActiveStep(0);
  }

@material-ui/styles has a peer dependency on react >= 16.7.0-alpha.0 and react-dom >= 16.7.0-alpha.0 Update your react and react-dom dependencies to: @ material-ui / styles对react> = 16.7.0-alpha.0和react-dom> = 16.7.0-alpha.0具有对等依赖关系将您的react和react-dom依赖关系更新为:

"dependencies": {
    "react": "^16.7.0-alpha.2",
    "react-dom": "^16.7.0-alpha.2",
},

From what I can see, you are using a version of React that does not yet have support for hooks ( useXXX ) 从我所看到的,你使用的是一个尚未支持钩子的React版本( useXXX

It sometimes confuses me too, but latest as a version in your package.json actually means "Latest stable version". 它有时会让我感到困惑,但latestpackage.json的版本实际上意味着“最新的稳定版本”。
To use a version that supports hooks, you can use the version next for react as well as react-dom :) 要使用支持挂钩的版本,您可以使用next版本进行react以及react-dom :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React useContext 返回默认值 - React useContext returns default values 反应 useContext setState 不是函数 - react useContext setState is not a function 反应:默认 state 未在 useContext 中设置为道具 - React: Default state not being set as props in useContext react__WEBPACK_IMPORTED_MODULE_0___default.a.useContext 不是函数 -- 在 Material UI 中使用自动完成功能时 - react__WEBPACK_IMPORTED_MODULE_0___default.a.useContext is not a function -- When using Autocomplete in Material UI 我如何通过 function 和 state 来反应 useContext - How can ı pass function with state for react useContext 即使我提供了一个值,React useContext() 默认值也没有改变 - React useContext() default value has not changed even I provide a value React Hook "useContext" 在函数 "age" 中调用,它既不是 React 函数组件,也不是自定义的 React Hook 函数 - React Hook "useContext" is called in function "age" which is neither a React function component or a custom React Hook function React useContext 无法使用 setTimeout function 更新 state - React useContext doesn't work using setTimeout function to update the state 我如何在旧的 react render() function 中使用上下文? - How do i useContext with the old react render() function? 带有React useContext的Typescript接口 - Typescript interface with React useContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM