![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
js
||·····
一个需要认清自己的大学生
展开
-
React-hooks-useCallback
useCallbak 返回一个memoized(被记住的,备忘)的回调函数 // 官网示例 const memoizedCallbak = useCallback( ()=>{ doSomething(a,b); }, [a,b] ) 把内联回调函数及依赖项数组作为参数传入 useCallback,它将返回该回调函数的 memoized 版本,该回调函数仅在某个依赖项改变时才会更新。当你把回调函数传递给经过优化的并使用引用相等性去避免非必要渲染原创 2021-06-07 15:02:24 · 116 阅读 · 0 评论 -
React-hooks-useReducer
useReducer 这是一个额外的Hooks,在某些特殊场景可能会用到。 使用方式 // 使用方式 const [state, dispatch] = useReducer(reducer, initialArg, init); // 官网示例 function init(initialCount) { return {count: initialCount}; } function reducer(state, action) { switch (action.type) {原创 2021-06-07 15:01:33 · 71 阅读 · 0 评论 -
React-hooks-useContext
React-hooks-useContext 在学习之前我们先来看看我们在没有hooks之前使用Context, 使用Context是为了避免props多层传递的麻烦 // ###App.js import React, { createContext, Component } from "react" // foo作为默认数据被传入 const foo = { name: "wangzhan", age: 22 } export const {Provider, Consumer} =原创 2021-06-07 15:00:38 · 87 阅读 · 0 评论 -
React-Hooks-useEffect
React-Hooks-useEffect 1. Effect hook 可以让我们在函数式组件中执行副作用操作 // react官网示例 import React, { useState, useEffect } from 'react'; function Example() { const [count, setCount] = useState(0); // Similar to componentDidMount and componentDidUpdate: useEffect(原创 2021-06-01 15:48:40 · 187 阅读 · 0 评论