博客
关于我
hook钩子介绍
阅读量:304 次
发布时间: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/

你可能感兴趣的文章
MySQL函数简介
查看>>
mysql函数遍历json数组
查看>>
mysql分区表
查看>>
MySQL分层架构与运行机制详解
查看>>
MySQL分组查询
查看>>
Mysql分表后同结构不同名称表之间复制数据以及Update语句只更新日期加减不更改时间
查看>>
Mysql基础命令 —— 系统操作命令
查看>>
mysql备份
查看>>
mysql大批量删除(修改)The total number of locks exceeds the lock table size 错误的解决办法
查看>>
mysql存储登录_php调用mysql存储过程会员登录验证实例分析
查看>>
MySQL学习-group by和having
查看>>
MySQL学习-子查询及limit分页
查看>>
Mysql学习总结(24)——MySQL多表查询合并结果和内连接查询
查看>>
Mysql学习总结(26)——MySQL子查询
查看>>
Mysql学习总结(38)——21条MySql性能优化经验
查看>>
Mysql学习总结(58)——深入理解Mysql的四种隔离级别
查看>>
Mysql工作笔记006---Mysql服务器磁盘爆满了_java.sql.SQLException: Error writing file ‘tmp/MYfXO41p‘
查看>>
mysql手工注入
查看>>
Mysql数据库 InnoDB存储引擎中Master Thread的执行流程
查看>>
Mysql数据库B-Tree索引
查看>>