博客
关于我
hook钩子介绍
阅读量:292 次
发布时间:2019-03-03

本文共 808 字,大约阅读时间需要 2 分钟。

1.useEffect不带第二个参数

// Similar to componentDidMount and componentDidUpdate:  useEffect(() => {    // Update the document title using the browser API    document.title = `You clicked ${count} times`;  });

例子

import React, { useState, useEffect } from 'react';import { Button } from '@alifd/next';export default function Example() {  const [count, setCount] = useState(0);  // Similar to componentDidMount and componentDidUpdate:  // 加载和state更新的时候会触发  useEffect(() => {    console.log(`hook-----${new Date()}`);    console.log(`count ${count} times`);    // Update the document title using the browser API    document.title = `You clicked ${count} times`;  });  return (    

You clicked {count} times

);}

当组件第一次被加载进来的时候,控制台打印

 

当每次点击按钮'cclick me',控制台打印

 

转载地址:http://euvm.baihongyu.com/

你可能感兴趣的文章
并发情况下三种线程/并发安全
查看>>
windows 安装Eclipse win7为例
查看>>
希尔排序
查看>>
TreeView 中 SelectedNodeStyle 无效,selectedClass 无效的参考方案
查看>>
C#,asp.net,ashx处理session
查看>>
501 5.1.7 Invalid address
查看>>
foxmail 登录 exchange 2013 exchange 2016
查看>>
Netty高性能原理和框架架构解析
查看>>
C/C++ * & : :: -> .等特殊符号
查看>>
C++中this指针
查看>>
(00)剑指 Offer 13. 机器人的运动范围
查看>>
剑指 Offer 18 删除链表的节点
查看>>
剑指 Offer 25. 合并两个排序的链表
查看>>
MySQL多表查询_索引_事务和隔离和事务原理_复习
查看>>
C# WinForm 监视文件变化程序
查看>>
Redis主从复制原理
查看>>
将本地已有的maven工程导入工作空间
查看>>
mysql中没有boolean,而是tinyint
查看>>
这个坑
查看>>
spring boot和sping的一些注解
查看>>