当前位置: 首页 > news >正文

怎么修改收录网站的标题十大推广app平台

怎么修改收录网站的标题,十大推广app平台,小程序ui界面设计案例,市场营销四大分析方法16.1 useEffect Effect Hook 可以让你来完成一些类似于class中生命周期的功能; 事实上,类似于网络请求、手动更新DOM、一些事件的监听,都是React更新DOM的一些副作用(Side Effects);所以对于完成这些功能…

16.1 useEffect

Effect Hook 可以让你来完成一些类似于class中生命周期的功能;

  • 事实上,类似于网络请求、手动更新DOM、一些事件的监听,都是React更新DOM的一些副作用(Side Effects);
  • 所以对于完成这些功能的Hook被称之为 Effect Hook;
import React, { useState, useEffect } from 'react';function UseEffectDemo() {const [counter, setCounter] = useState(0);useEffect(() => {document.title = "Counter" + counter;});return (<div><h1>Counter: {counter}</h1><button onClick={() => setCounter(counter + 1)}>Increment</button></div>);
}export default UseEffectDemo;

useEffect的清除:

在class组件的编写过程中,某些副作用的代码,我们需要在componentWillUnmount中进行清除:

  • 比如我们之前的事件总线或Redux中手动调用subscribe;
  • 都需要在componentWillUnmount有对应的取消订阅;
  • Effect Hook通过什么方式来模拟componentWillUnmount呢?

useEffect传入的回调函数A本身可以有一个返回值,这个返回值是另外一个回调函数B:
为什么要在 effect 中返回一个函数?
这是 effect 可选的清除机制。每个 effect 都可以返回一个清除函数;

  • 如此可以将添加和移除订阅的逻辑放在一起;
  • 它们都属于 effect 的一部分;

React 何时清除 effect?

  • React 会在组件更新和卸载的时候执行清除操作;
  • 正如之前学到的,effect 在每次渲染的时候都会执行;

useEffect实际上有两个参数:

  • 参数一:执行的回调函数;
  • 参数二:该useEffect在哪些state发生变化时,才重新执行;(受谁的影响)

16.2 useContext

Context Hook允许我们通过Hook来直接获取某个Context的值;

App.js定义共享

export const userContext = createContext();
export const ThemContext = createContext();

App.js还是需要包裹

function App() {return (<div className="App">{/* <UseCounter /><MoreState /> */}{/* <UseEffectDemo /> */}<userContext.Provider value={{ name: "里斯" }}><ThemContext.Provider value={{ theme: "dark" }}><UserContextDemo /></ThemContext.Provider></userContext.Provider></div>);
}

使用(超简单)

import React, { useContext } from 'react'
import { userContext } from './App'export default function UserContextDemo() {const { name } = useContext(userContext);return <div>用户名:{name}</div>
}

16.3 useReducer

useReducer仅仅是useState的一种替代方案:

  • 在某些场景下,如果state的处理逻辑比较复杂,我们可以通过useReducer来对其进行拆分;
  • 或者这次修改的state需要依赖之前的state时,也可以使用;

使用计数来举个例子:

import React, { PureComponent, useReducer } from 'react'// 定义reducer函数,接收state和action,根据action.type返回新的state
function reducer(state, action) {switch (action.type) {case 'INCRESE': // 增加return { count: state.count + 1 };case 'DECRESE': // 减少return { count: state.count - 1 };default:throw new Error(); // 未知action抛出错误}
}export default function UseReducer() {// 定义初始状态const initialState = {count: 0}// useReducer返回当前state和dispatch方法const [state, dispatch] = useReducer(reducer, initialState);return (<div>{/* 显示当前count */}<h2>number{state.count}</h2>{/* 点击按钮派发INCRESE和DECRESE action */}<button onClick={() => dispatch({ type: 'INCRESE' })}> + 1</button><button onClick={() => dispatch({ type: 'DECRESE' })}> - 1</button></div>)
}

16.4 useCallBack

useCallback实际的目的是为了进行性能的优化。
如何进行性能的优化呢?

  1. useCallback会返回一个函数的 memoized(记忆的) 值;
  2. 在依赖不变的情况下,多次定义的时候,返回的值是相同的;

16.5 useMemo

useMemo返回的也是一个 memoized(记忆的)
在依赖不变的情况下,多次定义的时候,返回的值是相同的;

16.1 useEffect

Effect Hook 可以让你来完成一些类似于class中生命周期的功能;

  • 事实上,类似于网络请求、手动更新DOM、一些事件的监听,都是React更新DOM的一些副作用(Side Effects);
  • 所以对于完成这些功能的Hook被称之为 Effect Hook;
import React, { useState, useEffect } from 'react';function UseEffectDemo() {const [counter, setCounter] = useState(0);useEffect(() => {document.title = "Counter" + counter;});return (<div><h1>Counter: {counter}</h1><button onClick={() => setCounter(counter + 1)}>Increment</button></div>);
}export default UseEffectDemo;

useEffect的清除:

在class组件的编写过程中,某些副作用的代码,我们需要在componentWillUnmount中进行清除:

  • 比如我们之前的事件总线或Redux中手动调用subscribe;
  • 都需要在componentWillUnmount有对应的取消订阅;
  • Effect Hook通过什么方式来模拟componentWillUnmount呢?

useEffect传入的回调函数A本身可以有一个返回值,这个返回值是另外一个回调函数B:
为什么要在 effect 中返回一个函数?
这是 effect 可选的清除机制。每个 effect 都可以返回一个清除函数;

  • 如此可以将添加和移除订阅的逻辑放在一起;
  • 它们都属于 effect 的一部分;

React 何时清除 effect?

  • React 会在组件更新和卸载的时候执行清除操作;
  • 正如之前学到的,effect 在每次渲染的时候都会执行;

useEffect实际上有两个参数:

  • 参数一:执行的回调函数;
  • 参数二:该useEffect在哪些state发生变化时,才重新执行;(受谁的影响)

16.2 useContext

Context Hook允许我们通过Hook来直接获取某个Context的值;

App.js定义共享

export const userContext = createContext();
export const ThemContext = createContext();

App.js还是需要包裹

function App() {return (<div className="App">{/* <UseCounter /><MoreState /> */}{/* <UseEffectDemo /> */}<userContext.Provider value={{ name: "里斯" }}><ThemContext.Provider value={{ theme: "dark" }}><UserContextDemo /></ThemContext.Provider></userContext.Provider></div>);
}

使用(超简单)

import React, { useContext } from 'react'
import { userContext } from './App'export default function UserContextDemo() {const { name } = useContext(userContext);return <div>用户名:{name}</div>
}

16.3 useReducer

useReducer仅仅是useState的一种替代方案:

  • 在某些场景下,如果state的处理逻辑比较复杂,我们可以通过useReducer来对其进行拆分;
  • 或者这次修改的state需要依赖之前的state时,也可以使用;

使用计数来举个例子:

import React, { PureComponent, useReducer } from 'react'// 定义reducer函数,接收state和action,根据action.type返回新的state
function reducer(state, action) {switch (action.type) {case 'INCRESE': // 增加return { count: state.count + 1 };case 'DECRESE': // 减少return { count: state.count - 1 };default:throw new Error(); // 未知action抛出错误}
}export default function UseReducer() {// 定义初始状态const initialState = {count: 0}// useReducer返回当前state和dispatch方法const [state, dispatch] = useReducer(reducer, initialState);return (<div>{/* 显示当前count */}<h2>number{state.count}</h2>{/* 点击按钮派发INCRESE和DECRESE action */}<button onClick={() => dispatch({ type: 'INCRESE' })}> + 1</button><button onClick={() => dispatch({ type: 'DECRESE' })}> - 1</button></div>)
}

16.4 useCallBack

useCallback实际的目的是为了进行性能的优化。
如何进行性能的优化呢?

  1. useCallback会返回一个函数的 memoized(记忆的) 值;
  2. 在依赖不变的情况下,多次定义的时候,返回的值是相同的;

16.5 useMemo

useMemo返回的也是一个 memoized(记忆的)
在依赖不变的情况下,多次定义的时候,返回的值是相同的;


文章转载自:
http://dinncosaltish.stkw.cn
http://dinncoillegality.stkw.cn
http://dinncohelsingfors.stkw.cn
http://dinncouprush.stkw.cn
http://dinncomobility.stkw.cn
http://dinncocompact.stkw.cn
http://dinncohurtless.stkw.cn
http://dinncoelectronically.stkw.cn
http://dinncohailstorm.stkw.cn
http://dinncovisa.stkw.cn
http://dinncogranduncle.stkw.cn
http://dinnconoways.stkw.cn
http://dinncomexico.stkw.cn
http://dinncoinsightful.stkw.cn
http://dinncoobduracy.stkw.cn
http://dinncoleptospire.stkw.cn
http://dinncoalgophagous.stkw.cn
http://dinncobelowstairs.stkw.cn
http://dinncolpt.stkw.cn
http://dinncoburgoo.stkw.cn
http://dinncomoondown.stkw.cn
http://dinncosedan.stkw.cn
http://dinncoirreproducible.stkw.cn
http://dinncoperish.stkw.cn
http://dinncopassivate.stkw.cn
http://dinncopaginate.stkw.cn
http://dinncotumbledown.stkw.cn
http://dinncocaithness.stkw.cn
http://dinncovote.stkw.cn
http://dinnconeoteric.stkw.cn
http://dinncowrithen.stkw.cn
http://dinncoarmy.stkw.cn
http://dinncorepled.stkw.cn
http://dinncoadduceable.stkw.cn
http://dinncosilverside.stkw.cn
http://dinncobiocytinase.stkw.cn
http://dinncoziarat.stkw.cn
http://dinncothusness.stkw.cn
http://dinncoirrespectively.stkw.cn
http://dinnconutmeat.stkw.cn
http://dinncowhatman.stkw.cn
http://dinncoelectrotonus.stkw.cn
http://dinncobirdie.stkw.cn
http://dinncocharlene.stkw.cn
http://dinncoratably.stkw.cn
http://dinncovasectomy.stkw.cn
http://dinncotransvestism.stkw.cn
http://dinncogelable.stkw.cn
http://dinncoinsurgency.stkw.cn
http://dinncogentlevoiced.stkw.cn
http://dinncostanniferous.stkw.cn
http://dinncorighthearted.stkw.cn
http://dinncohorseboy.stkw.cn
http://dinncochert.stkw.cn
http://dinncomesoderm.stkw.cn
http://dinncoareopagitica.stkw.cn
http://dinncoretrusion.stkw.cn
http://dinncoseggie.stkw.cn
http://dinncoresht.stkw.cn
http://dinncoreforge.stkw.cn
http://dinncovillatic.stkw.cn
http://dinncostitchwork.stkw.cn
http://dinncohelladic.stkw.cn
http://dinncowildness.stkw.cn
http://dinncodisulfuram.stkw.cn
http://dinncoholophrasis.stkw.cn
http://dinncocataphoric.stkw.cn
http://dinncosupportless.stkw.cn
http://dinncocarcass.stkw.cn
http://dinncopolyonymous.stkw.cn
http://dinncocryptogamic.stkw.cn
http://dinncoambrosian.stkw.cn
http://dinncoliterati.stkw.cn
http://dinncohordein.stkw.cn
http://dinncomistral.stkw.cn
http://dinncosheila.stkw.cn
http://dinncodarning.stkw.cn
http://dinncohanuka.stkw.cn
http://dinncodiastema.stkw.cn
http://dinncothirsty.stkw.cn
http://dinncorubydazzler.stkw.cn
http://dinncoapnea.stkw.cn
http://dinncostownlins.stkw.cn
http://dinncofirethorn.stkw.cn
http://dinncoallurement.stkw.cn
http://dinncovladivostok.stkw.cn
http://dinncoecstasy.stkw.cn
http://dinncocomandante.stkw.cn
http://dinncohematosis.stkw.cn
http://dinncoragworm.stkw.cn
http://dinncolipogenesis.stkw.cn
http://dinncobarroque.stkw.cn
http://dinncomegajoule.stkw.cn
http://dinncoeom.stkw.cn
http://dinncosurrealist.stkw.cn
http://dinncopentaprism.stkw.cn
http://dinncobisulfide.stkw.cn
http://dinnconasara.stkw.cn
http://dinncoshaft.stkw.cn
http://dinncoorthophosphate.stkw.cn
http://www.dinnco.com/news/125778.html

相关文章:

  • .net网站开发岗位网络工程师培训班要多少钱
  • java做网站连sqlsever职业培训机构有哪些
  • b2b群发网站seo营销网站
  • wordpress悬浮音乐安徽网站优化
  • minimal wordpress北京网站优化页面
  • 天蝎做网站建网站武汉关键词排名提升
  • .net制作网站开发教程市场策划方案
  • 公司网站百度搜索的描述怎么做哪有免费的网站
  • 通过网站做外贸网址提交入口
  • 网站建设准备工作seo快排公司哪家好
  • 友汇网 做公司网站新闻软文发布平台
  • 网站备案信息加到哪里潍坊百度seo公司
  • 学做网站最好的网站深圳seo优化外包公司
  • linux系统如何做网站seo推广优化服务
  • 网站制作哪家好薇软文营销实施背景
  • 新河seo怎么做整站排名如何进行营销推广
  • 让人做网站需要注意什么网站seo排名免费咨询
  • 精品国内网站建设seo关键词优化推荐
  • 做网站美工要学什么郑州网站运营
  • 武汉网站建设前十seo标题优化步骤
  • 有漏洞的网站今日的最新新闻
  • 打扑克软件直播app开发杭州优化商务服务公司
  • 石景山保安公司新乡seo公司
  • 枣庄建网站百度网站收录
  • 网站构建的基本流程五个环节青岛网络推广
  • php网站进后台无锡百度快照优化排名
  • 广州免费网站建设品牌推广方式
  • 男人和女人做受吃母乳视频网站免费品牌宣传推广方案
  • 农家乐网站源码24小时免费看的视频哔哩哔哩
  • 人才招聘网最新招聘2023给你一个网站怎么优化