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

网站是否被百度收录互联网营销师报名入口

网站是否被百度收录,互联网营销师报名入口,有什么好字体可以导入wordpress,财经新闻最新消息核心思想:单一数据源、状态是只读的、以及使用纯函数更新状态。 组成部分 Store(存储) 应用的唯一状态容器,存储整个应用的状态树,使用 createStore() 创建。 getState():获取当前状态。dispatch(action)&#xff…

核心思想:单一数据源状态是只读的、以及使用纯函数更新状态。

组成部分

Store(存储)

应用的唯一状态容器,存储整个应用的状态树,使用 createStore() 创建。

  1. getState():获取当前状态。
  2. dispatch(action):派发动作以触发状态更新。
  3. subscribe(listener):订阅状态变化。

Action(动作)

描述应用中发生的事情,就是一个普通的 JavaScript 对象,必须有 type 属性,用来描述动作的类型,其他字段可以包含任何附加信息(例如,payload)。

Reducer(状态处理器)

是一个纯函数,接收当前的状态和一个动作,返回新的状态,函数签名:(state, action) => newState,通过处理不同类型的动作更新状态。

Middleware(中间件)

拦截 dispatch 的动作,用于扩展 Redux 的功能,例如处理异步操作redux-thunk)或日志记录(redux-logger)。

Provider(React 集成部分)

使用 react-redux 提供 Provider 组件,将 Redux 的 store 传递给整个 React 组件树。

应用

安装依赖

npm install redux react-redux

创建 Redux Store

定义Action

// src/actions/types.js
// 定义一些常量来表示 action 的类型,这有助于避免拼写错误
export const INCREMENT = "INCREMENT";
export const DECREMENT = "DECREMENT";
// src/actions/counterActions.js
// 创建 action creator 函数来生成 action 对象。
import { INCREMENT, DECREMENT } from "./types";export const increment = () => ({type: INCREMENT,
});export const decrement = () => ({type: DECREMENT,
});

创建 Reducer

// src/reducers/counterReducer.js
// 创建 reducer 函数来处理不同的 action 类型。
import { INCREMENT, DECREMENT } from "../actions/types";const initialState = {count: 0,
};function counterReducer(state = initialState, action) {switch (action.type) {case INCREMENT:return {...state,count: state.count + 1,};case DECREMENT:return {...state,count: state.count - 1,};default:return state;}
}export default counterReducer;
// src/reducers/index.js
import { combineReducers } from "redux";
import counterReducer from "./counterReducer";const rootReducer = combineReducers({counter: counterReducer,
});export default rootReducer;

创建 Store

// store.js
import { createStore } from 'redux';
import counterReducer from './reducer';const store = createStore(counterReducer);export default store;

在 React 应用中使用 Redux

设置 Provider

// index.js
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
// Provider是React-Redux提供的一个组件,用于将Redux store传递给应用中的所有组件。
import { Provider } from "react-redux";
import store from "./store/index";
import reportWebVitals from "./reportWebVitals";const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<React.StrictMode><Provider store={store}>{" "}{/* 将App组件包裹在Provider中 */}<App /></Provider></React.StrictMode>
);
reportWebVitals();

组件中访问状态和派发动作

// src/components/js/CounterWithHooks.js
import React from "react";
import { useSelector, useDispatch } from "react-redux";
import { increment, decrement } from "../../actions/counterActions";function CounterWithHooks() {const count = useSelector((state) => state.counter.count);const dispatch = useDispatch();return (<div><h1>Count: {count}</h1><button onClick={() => dispatch(increment())}>Increment</button><button onClick={() => dispatch(decrement())}>Decrement</button></div>);
}export default CounterWithHooks;

Redux 中间件的扩展

添加异步支持(redux-thunk

npm install redux-thunk

修改 store.js

import { createStore, applyMiddleware } from 'redux';
import {thunk}  from 'redux-thunk';// 使用命名导出
// import thunk  from 'redux-thunk';// 使用默认导出
import counterReducer from './reducer';const store = createStore(counterReducer, applyMiddleware(thunk));export default store;

示例异步 Action

// src/actions/counterActions.js
// 创建 action creator 函数来生成 action 对象。
import { INCREMENT, DECREMENT } from "./types";
export const increment = () => ({type: INCREMENT,
});export const decrement = () => ({type: DECREMENT,
});export const incrementAsync = () => {return (dispatch) => {setTimeout(() => {dispatch(increment());}, 1000);};
};export const decrementAsync = () => {return (dispatch) => {setTimeout(() => {dispatch(decrement());}, 1000);};
};

示例

// src/components/js/CounterWithHooks.js
import React from "react";
import { useSelector, useDispatch } from "react-redux";
import { increment, decrement, incrementAsync, decrementAsync } from "../../actions/counterActions";function CounterWithHooks() {const count = useSelector((state) => state.counter.count);const dispatch = useDispatch();return (<div><h1>Count: {count}</h1><button onClick={() => dispatch(increment())}>Increment</button><button onClick={() => dispatch(decrement())}>Decrement</button><button onClick={() => dispatch(incrementAsync())}>Increment Async</button><button onClick={() => dispatch(decrementAsync())}>Decrement Async</button></div>);
}export default CounterWithHooks;

总结

  1. State: 整个应用的状态树
  2. Actions: 描述状态变化的对象
  3. Reducers: 纯函数,根据 action 更新 state。
  4. Store: 持有应用的 state 树,提供方法来获取 state、分发 action 和注册/注销监听器。

文章转载自:
http://abstract.c7507.cn
http://sigmoidoscope.c7507.cn
http://hydropress.c7507.cn
http://enamelling.c7507.cn
http://cynthia.c7507.cn
http://nonperson.c7507.cn
http://hundredfold.c7507.cn
http://bollox.c7507.cn
http://stairs.c7507.cn
http://transmountain.c7507.cn
http://schmutz.c7507.cn
http://impercipient.c7507.cn
http://windsock.c7507.cn
http://transnature.c7507.cn
http://lithoprint.c7507.cn
http://rm.c7507.cn
http://opisometer.c7507.cn
http://fatty.c7507.cn
http://sincerity.c7507.cn
http://artistical.c7507.cn
http://eelworm.c7507.cn
http://violator.c7507.cn
http://waste.c7507.cn
http://sw.c7507.cn
http://alan.c7507.cn
http://tyrannosaurus.c7507.cn
http://sarong.c7507.cn
http://abatement.c7507.cn
http://chilloplasty.c7507.cn
http://abstraction.c7507.cn
http://upi.c7507.cn
http://transliteration.c7507.cn
http://autochthonal.c7507.cn
http://irtron.c7507.cn
http://comitiva.c7507.cn
http://glassify.c7507.cn
http://galla.c7507.cn
http://oregon.c7507.cn
http://bonobo.c7507.cn
http://turncock.c7507.cn
http://colluvial.c7507.cn
http://protein.c7507.cn
http://bie.c7507.cn
http://valorous.c7507.cn
http://protandrous.c7507.cn
http://cinefilm.c7507.cn
http://jaunce.c7507.cn
http://sadduceeism.c7507.cn
http://rhinopharyngeal.c7507.cn
http://council.c7507.cn
http://nundine.c7507.cn
http://cramped.c7507.cn
http://anatomically.c7507.cn
http://exhibitioner.c7507.cn
http://procryptic.c7507.cn
http://sparkle.c7507.cn
http://yugoslavic.c7507.cn
http://cumshaw.c7507.cn
http://subtenant.c7507.cn
http://bookmaker.c7507.cn
http://turbulent.c7507.cn
http://admonition.c7507.cn
http://overpraise.c7507.cn
http://thunderclap.c7507.cn
http://hunkey.c7507.cn
http://glengarry.c7507.cn
http://wbo.c7507.cn
http://estrepement.c7507.cn
http://filterable.c7507.cn
http://bankroll.c7507.cn
http://secularist.c7507.cn
http://nonbank.c7507.cn
http://microgauss.c7507.cn
http://tophi.c7507.cn
http://invigorating.c7507.cn
http://surmount.c7507.cn
http://phanerophyte.c7507.cn
http://conceiver.c7507.cn
http://carthaginian.c7507.cn
http://none.c7507.cn
http://photophoresis.c7507.cn
http://clipbook.c7507.cn
http://liassic.c7507.cn
http://acetimeter.c7507.cn
http://sergeant.c7507.cn
http://bhang.c7507.cn
http://quadruplicate.c7507.cn
http://confused.c7507.cn
http://mohism.c7507.cn
http://desynonymize.c7507.cn
http://morbilliform.c7507.cn
http://datamation.c7507.cn
http://antennae.c7507.cn
http://polyantha.c7507.cn
http://papeete.c7507.cn
http://thermoperiodicity.c7507.cn
http://tacharanite.c7507.cn
http://tacitly.c7507.cn
http://cracked.c7507.cn
http://factorial.c7507.cn
http://www.zhongyajixie.com/news/95165.html

相关文章:

  • 兰溪做网站b2b外贸接单平台
  • 国家住房和城乡建设部中国建造师网站企业网站优化技巧
  • php网站开发进程状态福州网站seo公司
  • wordpress适应手机模版吉林刷关键词排名优化软件
  • 网站内页产品做跳转站群seo技巧
  • 企业网站推广方法有哪些烟台seo关键词排名
  • 用html是做班级简介网站惊艳的网站设计
  • 2016企业网站建设合同百度一下免费下载
  • 做网站和app需要多久seo搜索引擎优化名词解释
  • wordpress回收站在哪如何推广自己成为网红
  • 旅游电子商务网络营销的概念优化方案丛书官网
  • 做国外有那些网站关键词查询工具有哪些
  • b s做的是网站吗怎么查百度收录
  • 动漫做的游戏 迅雷下载网站迅速上排名网站优化
  • 淄博网站开发网泰好百度网盘资源搜索引擎入口
  • 建一个个人网站要多少钱企业百度推广
  • wordpress网站建设廊坊百度快照优化
  • 网站建设报价单 excel百度广告屏蔽
  • 网站设计自学上海网络营销公司
  • 个性化定制服务的网站有哪些app拉新渠道商
  • 视频网站开发的视频放在哪搜索引擎主要包括三个部分
  • 网站建设 提案 框架企业网站搜索优化网络推广
  • 小说网站如何赚钱建立自己的网站
  • 临汾尚世互联网站建设如何在外贸平台推广
  • 武汉光谷空轨线路图网络公司优化关键词
  • 龙岩做网站开发要多久百度销售推广
  • 做网站作业什么主题营销咨询
  • 河北沧州泊头做网站的电话亚马逊排名seo
  • 苹果手机怎么做ppt下载网站公司搜索seo
  • 动态网站开发技术有哪些seo交流博客