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

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

  2. react 创建组件 (四)Stateless Functional Component

    上面我们提到的创建组件的方式,都是用来创建包含状态和用户交互的复杂组件,当组件本身只是用来展示,所有数据都是通过props传入的时候,我们便可以使用Stateless Functional Compo ...

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

  4. [React] Creating a Stateless Functional Component

    Most of the components that you write will be stateless, meaning that they take in props and return ...

  5. React报错之React hook 'useState' cannot be called in a class component

    正文从这开始~ 总览 当我们尝试在类组件中使用useState 钩子时,会产生"React hook 'useState' cannot be called in a class compo ...

  6. React 16 源码瞎几把解读 【二】 react组件的解析过程

    一.一个真正的react组件编译后长啥样? 我们瞎几把解读了react 虚拟dom对象是怎么生成的,生成了一个什么样的解构.一个react组件不光由若干个这些嵌套的虚拟dom对象组成,还包括各种生命周 ...

  7. React Native Android原生模块开发实战|教程|心得|怎样创建React Native Android原生模块

    尊重版权,未经授权不得转载 本文出自:贾鹏辉的技术博客(http://blog.csdn.net/fengyuzhengfan/article/details/54691503) 告诉大家一个好消息. ...

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

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

随机推荐

  1. 最全mysql的复制和读写分离

    mysql的复制和mysql的读写分离从来就不是一个简单的话题,今天笔者就详细来记录一下我学习的mysql.   mysql日至类型有:二进制日志,事务日志,错误日志,一般查询日志,中继日志,慢查询日 ...

  2. myeclipse反编译安装 jd-gui.exe下载

    一:在线安装 1.Help->Install New Site Name:** Location:http://jd.benow.ca/jd-eclipse/update 二:手动安装 1.下载 ...

  3. javascript深度克隆函数deepClone

    javascript深度克隆函数deepClone function deepClone(obj) { var _toString = Object.prototype.toString; // nu ...

  4. cogs 466. [NOIP2009] 细胞分裂

    466. [NOIP2009] 细胞分裂 ★★   输入文件:cell.in   输出文件:cell.out   简单对比时间限制:1 s   内存限制:128 MB [问题描述]    Hanks ...

  5. Ubuntu PostgreSql主从切换

    主机:192.168.100.70 从机:192.168.100.71 通用配置(即主从都要配置) 修改/etc/postgresql/10/main/pg_hba.conf host all all ...

  6. ubuntu 休眠之后蓝牙鼠标无效果。

    ubuntu链接蓝牙鼠标之后.左上角蓝牙标志左下角应该有一个锁的标志. 可是休眠之后,蓝牙鼠标失效,锁没有了,点击按键,出来锁之后,立即消失. 运行两次例如以下命令能够解决: sudo hciconf ...

  7. chrome控制台常用技巧有哪些

    chrome控制台常用技巧有哪些 一.总结 一句话总结:别的里面支持的快捷键,chrome里面几乎都支持,比如sublime中的ctrl+d,其实真是一通百通,都差不多的 1.chrome如何快速切换 ...

  8. tensorfllow MNIST机器学习入门

    MNIST机器学习入门 这个教程的目标读者是对机器学习和TensorFlow都不太了解的新手.如果你已经了解MNIST和softmax回归(softmax regression)的相关知识,你可以阅读 ...

  9. 18.boost 图的拓扑排序

    运行结果: 代码示例: #include <iostream> #include <vector> #include <deque> #include <bo ...

  10. MYSQL binlog 日志内容查看

    记录mysql数据库真正执行更改的所有操作(DML语句),不包含那些没有修改任何数据的语句,不会记录select和show这样的语句. 二进制日志的作用: 1. 可以完成主从复制的功能 2. 进行恢复 ...