[React] Break up components into smaller pieces using Functional Components
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')
- );
[React] Break up components into smaller pieces using Functional Components的更多相关文章
- [Vue @Component] Write Vue Functional Components Inline
Vue's functional components are small and flexible enough to be declared inside of .vue file next to ...
- [React] Return a list of elements from a functional component in React
We sometimes just want to return a couple of elements next to one another from a React functional co ...
- [Vue] Load components when needed with Vue async components
In large applications, dividing the application into smaller chunks is often times necessary. In thi ...
- [React] Refactor a Stateful List Component to a Functional Component with React PowerPlug
In this lesson we'll look at React PowerPlug's <List /> component by refactoring a normal clas ...
- React 中的函数式思想
函数式编程简要概念 函数式编程中一个核心概念之一就是纯函数,如果一个函数满足一下几个条件,就可以认为这个函数是纯函数了: 它是一个函数(废话): 当给定相同的输入(函数的参数)的时候,总是有相同的输出 ...
- TED演讲:别不信,你只需20个小时,就能学会任何事情!
https://www.bilibili.com/video/av50668972/?spm_id_from=333.788.videocard.3 two years ago, my life ch ...
- type Props={};
Components Learn how to type React class components and stateless functional components with Flow Se ...
- [React] Make Compound React Components Flexible
Our current compound component implementation is great, but it's limited in that users cannot render ...
- [React] Intro to inline styles in React components
React lets you use "inline styles" to style your components; inline styles in React are ju ...
随机推荐
- JavaScript--数据结构与算法之排序
排序总结————常见的排序 常见的9中排序(冒泡,选择,插入(二分插入,希尔),归并,快速,堆,计数,基数,桶排序)可分为两类 比较排序:冒泡,选择,插入(二分插入,希尔),归并,堆,快速 非比较排序 ...
- python 新模块或者包的安装方法
主要介绍通过pip自动工具来安装需要的包. 1,先安装pip 下载pip的包(包括setup.py文件) cmd载入到pip本地文件所在路径,使用命令进行安装. python setup.py ins ...
- 洛谷——U10783 名字被和谐了
https://www.luogu.org/problem/show?pid=U10783 题目背景 众所周知,我们称g是a的约数,当且仅当g是正数且a mod g = 0. 众所周知,若g既是a的约 ...
- OC文件操作、获取文件属性
#import <Foundation/Foundation.h> //获取文件的属性 int main(int argc, const char * argv[]) { @autorel ...
- C# foreach 循环遍历数组
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...
- golang matrix
package main import ( "fmt" "go.matrix-go1" //比较有名的关于Matrix在golang中的方法库 "st ...
- SQL server 错误代码对比表
0 操作成功完毕. 1 功能错误. 2 系统找不到指定的文件. 3 系统找不到指定的路径. 4 系统无法打开文件. 5 拒绝訪问. 6 句柄无效. ...
- logback--How do I configure an AsyncAppender with code? 转载
原文地址:https://github.com/tony19/logback-android/issues/54 Please provide an example of how to configu ...
- 洛谷—— P1765 手机_NOI导刊2010普及(10)
https://www.luogu.org/problem/show?pid=1765#sub 题目描述 一般的手机的键盘是这样的: 1 2 abc 3 def 4 ghi 5 jkl 6 mno 7 ...
- TransE论文剩余部分
4.3链接预測 表3:链接预測结果.不同方法的性能. 整体结果 表3显示了全部数据集全部方法的比較. 与预期结果一致,经过过滤设置的结果具有较低的平均排名和较高的hits@10,相信在链接预測方面对各 ...