对列表进行 react 和使用有点新,不确定为什么我的代码没有按要求执行,当我调用该方法时它只显示纯 html
我尝试将其放在标签之间,但没有任何效果
有人可以指出我做错了什么吗?
import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import List from './List'
class App extends Component { //different
render() { //different
// The rest of the file is the same
return(
<div className="App">
Liste();
</div>)
};
}
function Liste(){
const names=['d','d']
return(<div>
<h2>{names[0]}</h2>
<h2> {names[1]}</h2>
</div>)
}
export default App;
最佳答案
您的 Liste
函数是一个函数组件,因此需要像任何其他 React 组件一样包含它,而不是作为函数执行。只需将应用程序组件中的 return 语句替换为
return(
<div className="App">
<Liste />;
</div>)
};
您可以通过此链接学习语法 - https://devhints.io/react
关于javascript - React 调用函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60472122/