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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. [Vue] Load components when needed with Vue async components

    In large applications, dividing the application into smaller chunks is often times necessary. In thi ...

  4. [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 ...

  5. React 中的函数式思想

    函数式编程简要概念 函数式编程中一个核心概念之一就是纯函数,如果一个函数满足一下几个条件,就可以认为这个函数是纯函数了: 它是一个函数(废话): 当给定相同的输入(函数的参数)的时候,总是有相同的输出 ...

  6. TED演讲:别不信,你只需20个小时,就能学会任何事情!

    https://www.bilibili.com/video/av50668972/?spm_id_from=333.788.videocard.3 two years ago, my life ch ...

  7. type Props={};

    Components Learn how to type React class components and stateless functional components with Flow Se ...

  8. [React] Make Compound React Components Flexible

    Our current compound component implementation is great, but it's limited in that users cannot render ...

  9. [React] Intro to inline styles in React components

    React lets you use "inline styles" to style your components; inline styles in React are ju ...

随机推荐

  1. Express简介、安装

    Express 基于Node.js平台,快速.开放.极简的web开发框架,是目前最流行的基于Node.js的web开发框架,它提供一系列强大的功能,比如: 路由控制 参数获取 send和sendFil ...

  2. Python基础教程之第1章 基础知识

    #1.1 安装Python #1.1.1 Windows #1.1.2 Linux和UNIX #1.1.3 Macintosh #1.1.4 其它公布版 #1.1.5 时常关注.保持更新 #1.2 交 ...

  3. what happens when changing the DOM via innerHTML

    what happens when changing the DOM via innerHTML

  4. Thinkphp5创建控制器

    今天我们就来创建一个控制器: <?php namespace app\index\controller; use think\Controller; class Test extends Con ...

  5. css实现背景半透明文字不透明的效果

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  6. 【CS Round #46 (Div. 1.5) B】Letters Deque

    [链接]h在这里写链接 [题意] 让你把一个正方形A竖直或水平翻转. 问你翻转一次能不能把A翻转成B [题解] 有说一定要恰好为1次. 并不是说A和B相同就一定不行. [错的次数] 2 [反思] 自己 ...

  7. [D3] Animate Transitions in D3 v4

    D3 makes it easy to add meaningful animations to your data visualizations. Whether it’s fading in ne ...

  8. Qt产生随机数(两种方法)

    第一种方法 #include <QTime> QTime time; time= QTime::currentTime(); qsrand(time.msec()+time.second( ...

  9. TCP超时重传机制

    TCP协议在能够发送数据之前就建立起了"连接".要实现这个连接,启动TCP连接的那一方首先将发送一个SYN数据包.这只是一个不包含数据的数据包, 然后,打开SYN标记.如果另一方同 ...

  10. Loadrunner--运行场景报Socket descriptor not found错误

    今天早上在使用LoadRunner时,报了如下的错误,开始并未看错误以为是录制问题引起,就重新录制了一遍,简单施压看看错误是否还有,结果错误仍然有,如下所示: Error: Socket descri ...