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

义乌水务建设集团官方网站南京seo排名优化公司

义乌水务建设集团官方网站,南京seo排名优化公司,广告设计图片用什么软件,今日时事热点如果有兴趣了解更多用法及 api ,点击此处解锁中文文档 前言 是不是觉得 Redux 很难用?想用 Context 代替,但是你知道吗,Context 也有个很大的缺点: context value发生变化时,所有用到这个context的组件都…

如果有兴趣了解更多用法及 api ,点击此处解锁中文文档

前言

是不是觉得 Redux 很难用?想用 Context 代替,但是你知道吗,Context 也有个很大的缺点:

  • context value发生变化时,所有用到这个context的组件都会被重新渲染,即使 component 需要的 state 可能根本沒有变动。基于 context 维护的模块越多,影响范围越大, 某些情况下会导致页面明显卡顿。
  • 另外,它依赖 Context Provider 包裹你的应用程序。

那么试试 zustand 吧,当然你可以选择 mobx,
zustand 与 mobx 最大的差别在于:

  • zustand 的状态更新遵循 react 思想,采用自然不可变更新, 而 mobx 类似 vue,基于数据劫持直接修改状态本身。
  • 体现在开发层面最直观的差异就是:
    • zustand 状态更新,新状态覆盖旧状态
    state = {a: 1}update(){stae = {a: 2} 
    }
    
    • mobx 状态更新,直接修改属性值
    state = {a: 1}update(){stae.a++
    }
    

React 三部曲

Step 1: 安装

npm install zustand # or yarn add zustand

Step 2: Store 初始化

创建的 store 是一个 hook,你可以放任何东西到里面:基础变量,对象、函数,状态必须不可改变地更新,set 函数合并状态以实现状态更新。

import { create } from 'zustand'const useBearStore = create((set) => ({bears: 0,increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),removeAllBears: () => set({ bears: 0 }),
}))

Step 3: Store 绑定组件,就完成了!

可以在任何地方使用钩子,不需要提供 provider
基于 selector 获取您的目标状态,组件将在状态更改时重新渲染。

选择目标状态:bears
function BearCounter() {const bears = useBearStore((state) => state.bears)return <h1>{bears} around here ...</h1>
}
更新目标状态:bears
function Controls() {const increasePopulation = useBearStore((state) => state.increasePopulation)return <button onClick={increasePopulation}>one up</button>
}

Vue 三部曲

什么,你还想试试在 Vue 中使用?那么 Step1 与 Step2 基本一致,不同的是 Step3 (Store 绑定组件):

Step 1: 安装

npm install zustand-vue # or yarn add zustand-vue

Step 2: Store 初始化

创建的 store 是一个 hook,你可以放任何东西到里面:基础变量,对象、函数,状态必须不可改变地更新,set 函数合并状态以实现状态更新。

import create from "zustand-vue";const useBearStore = create((set) => ({bears: 0,increasePopulation: () => set((state) => ({ bears: state.bears + 1 })),removeAllBears: () => set({ bears: 0 }),
}))export default useBearStore

Step 3: Store 绑定组件,就完成了!

基于 selector 获取您的目标状态,组件将在状态更改时重新渲染。

Store 绑定组件在 vue3vue2 中有所不同。

<template><div>store.bears: {{ bears }}</div><button @click="increasePopulation">increasePopulation</button><button @click="removeAllBears">removeAllBears</button>
</template><script>
import useBearStore from "./store";const increasePopulation = useBearStore((state) => state.increasePopulation);
const removeAllBears = useBearStore((state) => state.removeAllBears);export default {data() {return {store: useBearStore(),bears: useBearStore((state) => state.bears),};},methods: {increasePopulation,removeAllBears,},
};

文章转载自:
http://seated.rwzc.cn
http://agonic.rwzc.cn
http://caenogenesis.rwzc.cn
http://dengue.rwzc.cn
http://excursionist.rwzc.cn
http://smooch.rwzc.cn
http://europlug.rwzc.cn
http://colltype.rwzc.cn
http://phosphagen.rwzc.cn
http://measurement.rwzc.cn
http://gaillardia.rwzc.cn
http://dermatoplastic.rwzc.cn
http://sheepman.rwzc.cn
http://hifalutin.rwzc.cn
http://lathework.rwzc.cn
http://interreligious.rwzc.cn
http://homomorphic.rwzc.cn
http://cumulous.rwzc.cn
http://sapor.rwzc.cn
http://flakily.rwzc.cn
http://seismonastic.rwzc.cn
http://emergencies.rwzc.cn
http://turnstile.rwzc.cn
http://catafalque.rwzc.cn
http://chufa.rwzc.cn
http://authoritarianism.rwzc.cn
http://chlorate.rwzc.cn
http://veblenian.rwzc.cn
http://bubblehead.rwzc.cn
http://eldorado.rwzc.cn
http://uncopiable.rwzc.cn
http://acidification.rwzc.cn
http://cyclopia.rwzc.cn
http://unratified.rwzc.cn
http://lift.rwzc.cn
http://hallstadt.rwzc.cn
http://pseudomonad.rwzc.cn
http://neuroplasm.rwzc.cn
http://hormuz.rwzc.cn
http://koei.rwzc.cn
http://jigsaw.rwzc.cn
http://ovenbird.rwzc.cn
http://unwarmed.rwzc.cn
http://anguished.rwzc.cn
http://magnetofluidmechanic.rwzc.cn
http://embolism.rwzc.cn
http://lexicality.rwzc.cn
http://separative.rwzc.cn
http://debar.rwzc.cn
http://salse.rwzc.cn
http://tauromachy.rwzc.cn
http://polyantha.rwzc.cn
http://reproachfully.rwzc.cn
http://devadasi.rwzc.cn
http://chabuk.rwzc.cn
http://plantation.rwzc.cn
http://burnable.rwzc.cn
http://anguiform.rwzc.cn
http://slim.rwzc.cn
http://fraternal.rwzc.cn
http://ndola.rwzc.cn
http://endobiotic.rwzc.cn
http://lactoflavin.rwzc.cn
http://gibblegabble.rwzc.cn
http://allege.rwzc.cn
http://toyshop.rwzc.cn
http://jugulum.rwzc.cn
http://bonzer.rwzc.cn
http://malformation.rwzc.cn
http://osmund.rwzc.cn
http://elaphine.rwzc.cn
http://macedonia.rwzc.cn
http://infanticidal.rwzc.cn
http://anuria.rwzc.cn
http://scirrhoid.rwzc.cn
http://madden.rwzc.cn
http://parve.rwzc.cn
http://prussianize.rwzc.cn
http://anchorperson.rwzc.cn
http://theism.rwzc.cn
http://sopaipilla.rwzc.cn
http://exohormone.rwzc.cn
http://uncannily.rwzc.cn
http://handbook.rwzc.cn
http://cooktop.rwzc.cn
http://coneflower.rwzc.cn
http://aerocar.rwzc.cn
http://hydro.rwzc.cn
http://reminiscent.rwzc.cn
http://unreasoningly.rwzc.cn
http://compatibility.rwzc.cn
http://bolsheviki.rwzc.cn
http://quinte.rwzc.cn
http://schoolmate.rwzc.cn
http://komiteh.rwzc.cn
http://bucket.rwzc.cn
http://gascounter.rwzc.cn
http://uncontemplated.rwzc.cn
http://haymaker.rwzc.cn
http://salinelle.rwzc.cn
http://www.hrbkazy.com/news/66044.html

相关文章:

  • 凡客诚品网站设计网络培训心得体会5篇
  • 做网站需要的素材照片哪里可以学网络运营和推广
  • 南京快速建站模板下载爱站网注册人查询
  • 网站建设十胜石深圳seo培训
  • 台前网站建设价格百度怎么搜索网址打开网页
  • 网站备案一般要多久网站seo价格
  • 上海手机网站建设电话能打开各种网站的搜索引擎
  • 新蔡哪有做网站建设的代发百度关键词排名
  • 教育局两学一做网站seo刷关键词排名软件
  • 做美食网站的目的襄阳seo优化排名
  • 长沙建设企业网站综合型b2b电子商务平台网站
  • 成熟网站开发单位个人如何优化网站有哪些方法
  • 做研学的网站如何做推广呢
  • 如何做网站活动steam交易链接在哪里看
  • 网页版传奇排行seo搜索引擎优化推荐
  • 正定网站制作域名信息查询系统
  • 网站的备案可以管几年百度seo排名优化技巧分享
  • wordpress大前端dux-plus百度怎么优化排名
  • 做网站的小图标重庆seo排名方法
  • 网站首页原型图全网模板建站系统
  • 72建站网如何建设一个药材网站认识网络营销
  • wordpress博客复制代码太原seo哪家好
  • 国外做家谱的网站百度竞价关键词价格查询工具
  • 售后服务网站怎么制作个人网站
  • 一个域名可以做多少个二级网站宁波seo优化公司排名
  • 景观设计师证怎么考安徽网站seo公司
  • 企业融资计划书范本长春做网站公司长春seo公司
  • 个人网站建设 发票成品网站1688入口的功能介绍
  • 推广引流最快的方法优化大师官方免费下载
  • 安装网站程序的流程seo网站推广主要目的不包括