[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 class component with state and handlers to a functional component powered by React PowerPlug.
import React from "react";
import { render } from "react-dom";
import random from "random-name";
import { List } from "react-powerplug"; function MyList() {
return (
<List initial={["Jago", "Cinder", "Glacius", "Riptor"]}>
{({ list, push, pull }) => (
<div>
<div className="block">
{list.map(name => (
<span
key={name}
className="tag is-link"
style={{ marginRight: 10 }}
>
<button
className="delete is-small"
style={{ marginRight: 5 }}
onClick={() => pull(n => n === name)}
/>
{name}
</span>
))}
</div>
<button
className="button is-success"
onClick={() => push(random.first())}
>
Add Random Name
</button>
</div>
)}
</List>
);
}
render(<MyList />, document.getElementById("root"));
[React] Refactor a Stateful List Component to a Functional Component with React PowerPlug的更多相关文章
- [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 ...
- react 创建组件 (四)Stateless Functional Component
上面我们提到的创建组件的方式,都是用来创建包含状态和用户交互的复杂组件,当组件本身只是用来展示,所有数据都是通过props传入的时候,我们便可以使用Stateless Functional Compo ...
- [React] Write a stateful Component with the React useState Hook and TypeScript
Here we refactor a React TypeScript class component to a function component with a useState hook and ...
- [React] Creating a Stateless Functional Component
Most of the components that you write will be stateless, meaning that they take in props and return ...
- React报错之React hook 'useState' cannot be called in a class component
正文从这开始~ 总览 当我们尝试在类组件中使用useState 钩子时,会产生"React hook 'useState' cannot be called in a class compo ...
- React 16 源码瞎几把解读 【二】 react组件的解析过程
一.一个真正的react组件编译后长啥样? 我们瞎几把解读了react 虚拟dom对象是怎么生成的,生成了一个什么样的解构.一个react组件不光由若干个这些嵌套的虚拟dom对象组成,还包括各种生命周 ...
- React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块
尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...
- [Vue warn]: Attribute "id" is ignored on component <div> because the component is a fragment instanc
今天在使用vue框架搭建环境时,遇到这个错误提示: [Vue warn]: Attribute "id" is ignored on component <div> b ...
- [React] Refactor a Class Component with React hooks to a Function
We have a render prop based class component that allows us to make a GraphQL request with a given qu ...
随机推荐
- 最全mysql的复制和读写分离
mysql的复制和mysql的读写分离从来就不是一个简单的话题,今天笔者就详细来记录一下我学习的mysql. mysql日至类型有:二进制日志,事务日志,错误日志,一般查询日志,中继日志,慢查询日 ...
- Python学习笔记(7)字典
2019-03-07 字典(dict): (1)字典用大括号({})定义,字典由多个键及其对应的值组合而成,每一对键值组合称为项. (2)字典的键唯一,但是值可以是任何(不可变的)数据类型(整型,字符 ...
- [luogu] P4823 [TJOI2013]拯救小矮人(贪心)
P4823 [TJOI2013]拯救小矮人 题目描述 一群小矮人掉进了一个很深的陷阱里,由于太矮爬不上来,于是他们决定搭一个人梯.即:一个小矮人站在另一小矮人的 肩膀上,知道最顶端的小矮人伸直胳膊可以 ...
- lua创建文件
详细描述:http://www.runoob.com/lua/lua-file-io.html Lua文件I/O 1. 简单模式 -- 以只读方式打开文件-- file = io.open (file ...
- HDU 4313 Contest 2
很明显的树形DP了.但网上有的说可以用并查集.... 考虑一棵子树,当根结点有机器人时,则必定所有子树都要和根结点断开,而根结点向上返回的路径值则为其父结点与根结点连边的权值. 当根结点安全时,假设其 ...
- POJ 3088
已知n,求n中取k(k<=n)个数组成的m(m<=n)个的集合的排列数. 于是,可以枚举选出k个数及枚举m个集合.这个很明显是二类斯特林数.而集合有序,则乘上m! #include < ...
- SQL编码中注意的性能问题
1.选择合适的数据类型 为列选择最小化的数据类型 假设一列中的文本长度不一,使用VARCHAR而不是CHAR 不存储Unicode不要使用NVARCHAR或者NCHAR 假设一行的长度不超过8000, ...
- c3p0在spring中的配置
在大家的开发和学习其中应该经经常使用到数据库的连接和使用,只是连接 的方式就有非常多种方式了,例如说用最最简单的JDBC 也好,还实用比 较复杂一点的就是数据库连接池.当然还有使用DBCP的连接的,各 ...
- MongoDB基本概念和安装配置
基本概念 MongoDB直接存储JSON. 有了NoSQL数据库之后,可以直接在业务层将数据按照指定的结构进行存储. NO SQL NoSQL 1 数据库 数据库 2 表 集合 3 行 文档 4 列 ...
- mobiscroll手机端插件 好用(时间、日历、颜色)
http://demo.mobiscroll.com/range/rangepickertime/ 下载地址:http://download.mobiscroll.com/trial#/ios/dat ...