【发布时间】:2019-11-05 05:49:28
【问题描述】:
我正在学习 react.js 状态,每次运行此代码时都会收到错误“状态”被分配了一个值,但从未使用过 no-unused-vars
我尝试制作类APP而不是函数APP
import React from 'react';
import './App.css';
import Person from './Person/Person'
function App() {
const state = {
persons: [
{ name :'max', age : 28},
{ name:'manu', age : 29},
{ name:'adel', age : 30}
]
}
return (
<div className="App">
<h1> Hello world</h1>
<button> Switch name </button>
<Person name= {this.state.persons[0].name} age= {this.state.persons[0].age} ></Person>
<Person name= {this.state.persons[1].name} age= {this.state.persons[1].age} >hello eslam </Person>
<Person name= {this.state.persons[2].name} age= {this.state.persons[2].age} ></Person>
</div>
);
}
export default App;
【问题讨论】:
标签: reactjs react-hooks