[React] Break up components into smaller pieces using Functional Components
2024-08-31 20:24:42
We are going to ensure our app is structured in a clear way using functional components. Then, we are going to pass those components state values from the parent class component.
const { Component } = React; const InputField = (props) => {
return (
<input type="text" />
)
} const Button = (props) => {
return (
<button>Go</button>
)
} const List = (props) => {
console.log(props)
return (
<ul>
{props.todos.map(todo => {
return <li key={todo.id}>{todo.name}</li>
})}
</ul>
)
} class App extends Component {
constructor() {
super()
this.state = {
todos: [
{id: 0, name: 'foo'},
{id: 1, name: 'bar'},
{id: 2, name: 'baz'}
]
}
} render() {
return (
<div className="App">
<InputField />
<Button />
<List todos={this.state.todos} />
</div>
)
}
} ReactDOM.render(
<App />,
document.getElementById('root')
);
最新文章
- ttf,eot,woff,svg,字体格式介绍及使用方法
- 用Eclipse搭建ssh框架
- Android UI性能优化实战, 识别View中的性能问题
- 今天执行grep命令差点把服务器搞崩
- AJAX-----04XMLHttpRequest对象的ajax
- c#之Redis实践list,hashtable
- hdu 3280 动态规划
- .Net Core 中的包、元包与框架(Packages, Metapackages and Frameworks)
- gridControl 中CellValueChanged,ShowingEditor,CustomDrawCell的用法
- SSM-SpringMVC-33:SpringMVC中拦截器Interceptor讲解
- app与手机其他软件交互测试
- 应用 memcached 提升站点性能
- Java静态方法为什么不能访问非静态方法
- PowerDesigner 12.5 汉化包-CSDN下载
- OpenGL 画出雷达动态扫描效果(二) 非底图
- poj 2599 单调栈 ***
- ReactNative——UI1.登录界面样式设置
- HBase数据访问的一些常用方式
- fortran打开文件“” /dde错误
- node express+mysql搭建简易API服务—body-parser中间件