[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 ...
随机推荐
- js获得 json对象的个数(长度)
function getJsonObjLength(jsonObj) { var Length = 0; for (var item in jsonObj) { Length++; } return ...
- MyBatis学习总结(2)——使用MyBatis对表执行CRUD操作
一.使用MyBatis对表执行CRUD操作--基于XML的实现 1.定义sql映射xml文件 userMapper.xml文件的内容如下: <?xml version="1.0&quo ...
- DQL命令(查询)
select *或字段1,字段2... from 表名 [where 条件] 提示:*符号表示取表中所有列:没有where语句表示 查询表中所有记录:有wh ...
- poj2385(dp)
题目链接:http://poj.org/problem?id=2385 Apple Catching Time Limit: 1000MS Memory Limit: 65536K Total S ...
- crm操作报价单实体
using System; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft ...
- Java多线程之~~~线程安全容器的非堵塞容器
在并发编程中,会常常遇到使用容器.可是假设一个容器不是线程安全的.那么他在多线程的插入或者删除的过程 中就会出现各种问题.就是不同步的问题.所以JDK提供了线程安全的容器,他能保证容器在多线程的情况下 ...
- Java获取项目路径下的方法(全)
平时敲代码的时候,非常多时候提示文件找不到,而抛出了异常,如今整理例如以下 一 相对路径的获得 说明:相对路径(即不写明时候究竟相对谁)均可通过下面方式获得(不论是一般的java项目还是web项目) ...
- bzoj1103: [POI2007]大都市meg(树链剖分)
1103: [POI2007]大都市meg 题目:传送门 简要题意: 给你一棵树,给出每条边的权值,两个操作:1.询问根到编号x的最短路径的权值和 2.修改一条边的边权 题解: 很明显啊,看懂了题基 ...
- 使用dispatch_once实现单例
很多人实现单例会这样写: @implementation XXClass + (id)sharedInstance { static XXClass *sharedInstance = nil; @s ...
- 图论之tarjan缩点
缩点,就是把一张有向有环图中的环缩成一个个点,形成一个有向无环图. 首先我介绍一下为什么这题要缩点(有人肯定觉得这是放屁,这不就是缩点的模板题吗?但我们不能这么想,考试的时候不会有人告诉你打什么板上去 ...