私が持っている連絡先罰金に動作します以下のクラスを。
次に、Recordlistという関数を連絡先クラスに追加します。以下のように関数をcomponentDidMount()関数に渡すと、何も表示されません。連絡先クラスの直下で関数を渡すと、予期しないエラートークンがスローされます。
componentDidMount(){
function RecordList() {
const userid = 101;
const username = 'henry';
alert(username);
return (
<ul>
<b>Hey {username} the function is working</b>
</ul>
);
}
}
この関数のコンテンツを連絡先クラスに追加して表示するにはどうすればよいですか。回避策はありがたいです
import React, { Component } from "react";
import ReactDOM from 'react-dom';
class Contact extends React.Component{
//class Contact extends Component {
constructor(props) {
super(props);
this.state = {
id: ''
};
}
render() {
return (
<div>
<h2>Hello welcome to contact page</h2>
</div>
);
}
}
export default Contact;
import React, { Component } from "react";
import ReactDOM from 'react-dom';
class Contact extends React.Component{
constructor(props) {
super(props);
this.state = {
id: ''
};
}
RecordList() {
const userid = 101;
const username = 'henry';
return (
<ul>
<b>Hey {username} the function is working</b>
</ul>
);
}
render() {
return (
<div>
<h2>Hello welcome to contact page</h2>
{this.RecordList()}
</div>
);
}
}
export default Contact;
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加