所以我的反应代码中没有任何地方使用 useContext 属性。我有一个 npm 包,其中有一个已编译的 webpack 文件,其中有一个组件。当我尝试在我的 React 应用程序中使用该组件时,它会抛出错误 Uncaught TypeError: Cannot read properties of null (reading 'useContext')。组件函数在那里并输出一个反应对象。它只是在使用时破坏页面。现在我研究了 useContext 是什么,我相信它与状态有关。
所以下面是我将在我的反应应用程序中使用的输入组件
import React from 'react';
import {TextField} from '@mui/material';
class Input extends React.Component {
constructor(props){
super(props)
}
render(){
return (
<div className="input" style={{position:"relative",left:this.props.tabOver? this.props.tabOver.toString()+"px":"0px"}}>
<label style={{display:"block", width:"100%",position:"relative", margin: "5px"}}> {this.props.labelName}</label>
<TextField
size="small"
onChange={(e)=>{this.props.update(e.target.value)}}
value={this.props.value}
label={this.props.label? this.props.label:"type here"}
error={this.props.error? this.props.error:false}
required={this.props.required? this.props.required:false}
disabled={this.props.disabled? this.props.disabled:false}
helperText={this.props.helperText? this.props.helperText:""}
InputProps={{ style: { fontSize: this.props.InputProps? this.props.InputProp:10 } }}
InputLabelProps={{ style: { fontSize: (this.props.InputLabelProps? this.props.InputLabelProps:12) } …Run Code Online (Sandbox Code Playgroud)