【发布时间】:2021-04-13 17:24:35
【问题描述】:
我有此代码,但收到错误消息:
src/App.js 第 5:11 行:“state”被分配了一个值,但从未使用过 no-unused-vars。
我做错了什么? 感谢您的帮助!
import Some from './Some/Some';
const App = () => {
const state = ({
persons: [
{name: 'Connor', text: 'This is first.'},
{name: 'Megan', text: 'This is second.'},
{name: 'Jcob', text: 'This is third.'}
]
}
);
return (
<div className="App">
<h1>Hi, React!</h1>
<Some name={this.state.persons[0].name} text={this.state.persons[0].text} />
<Some name={this.state.persons[1].name} text={this.state.persons[1].text} />
<Some name={this.state.persons[2].name} text={this.state.persons[2].text} />
</div>
);
}
export default App;
【问题讨论】:
-
this.state?看起来你在一个功能组件中(没有“this”)
标签: reactjs