[英]Error when passing parameters in components in react using Typescript
When I pass the value parameter from App component to App2 component in react using typescript, it is giving an error 当我使用typescript将值参数从App组件传递给App2组件时,它会给出错误
Property 'value' does not exist on type 'IntrinsicAttributes & IntrinsicClassAttributes<App2> & Readonly<{ children?: ReactNode; }> & Read...
The code of App.tsx is App.tsx的代码是
import * as React from "react";
import './App.css';
import App2 from './App2';
class App extends React.Component<any,any>{
public render(){
return(
<div>
<h1>
<App2 value = {5}/>
</h1>
</div>
)
}
}
export default App;
and the code of App2 component is :- 而App2组件的代码是: -
import * as React from "react";
class App2 extends React.Component{
public render(){
return(
<div>
<h4>Hello world</h4>
</div>
)
}
}
export default App2;
You need to specify the type for the properties to tell the compiler what properties are valid on the App2
component and what their types are: 您需要指定属性的类型,以告诉编译器哪些属性在
App2
组件上有效以及它们的类型是什么:
class App2 extends React.Component<{ value: number }>{
public render() {
return (
<div>
<h4>Hello world</h4>
</div>
)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.