
hook钩子介绍
发布日期:2021-05-06 19:34:58
浏览次数:11
分类:技术文章
本文共 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',控制台打印
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年03月26日 01时14分53秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Redis支持的5种数据类型
2019-03-03
FreeRTOS学习笔记(9)——内存管理
2019-03-03
FreeRTOS学习笔记(10)——中断管理
2019-03-03
CC2640R2F学习笔记(1)——搭建环境、编译烧写
2019-03-03
ESP8266学习笔记(10)——官方WebServer
2019-03-03
CC2640R2F学习笔记(6)——UART串口使用
2019-03-03
SHELL命令
2019-03-03
数据结构与算法分析 一、引言(本书内容 + 递归简论)
2019-03-03
Oracle的高级复制、流复制、备库的区别
2019-03-03
redis命令学习
2019-03-03
自然划分的3-4-5规则
2019-03-03
剑指offer Leetcode 37.序列化二叉树
2019-03-03
剑指offer Leetcode 39.数组中出现次数超过一半的数字
2019-03-03
机器学习--sklearn之k-近邻算法
2019-03-03
Latex中cases环境引入报错
2019-03-03
Latex排版的时候把图片放在指定位置
2019-03-03
Latex如何将题目和作者左对齐
2019-03-03
用 Python 把你的朋友变成表情包(鼠标事件提取 ROI 版)
2019-03-03
Tensorflow2.0:基于循环卷积网络预测剩余寿命
2019-03-03
联邦学习(一):通过卷积神经网络对 emnist 数据集分类
2019-03-03