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

成都专业网站建设公司太原市建设厅网站

成都专业网站建设公司,太原市建设厅网站,怎么快速推广网站,网站规划与建设是什么意思核心思想#xff1a;单一数据源、状态是只读的、以及使用纯函数更新状态。 组成部分 Store#xff08;存储#xff09; 应用的唯一状态容器#xff0c;存储整个应用的状态树,使用 createStore() 创建。 getState()#xff1a;获取当前状态。dispatch(action)#xff…核心思想单一数据源、状态是只读的、以及使用纯函数更新状态。 组成部分 Store存储 应用的唯一状态容器存储整个应用的状态树,使用 createStore() 创建。 getState()获取当前状态。dispatch(action)派发动作以触发状态更新。subscribe(listener)订阅状态变化。 Action动作 描述应用中发生的事情就是一个普通的 JavaScript 对象必须有 type 属性用来描述动作的类型其他字段可以包含任何附加信息例如payload。 Reducer状态处理器 是一个纯函数接收当前的状态和一个动作返回新的状态函数签名(state, action) newState,通过处理不同类型的动作更新状态。 Middleware中间件 拦截 dispatch 的动作用于扩展 Redux 的功能例如处理异步操作redux-thunk或日志记录redux-logger。 ProviderReact 集成部分 使用 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.StrictModeProvider 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 (divh1Count: {count}/h1button onClick{() dispatch(increment())}Increment/buttonbutton 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 (divh1Count: {count}/h1button onClick{() dispatch(increment())}Increment/buttonbutton onClick{() dispatch(decrement())}Decrement/buttonbutton onClick{() dispatch(incrementAsync())}Increment Async/buttonbutton onClick{() dispatch(decrementAsync())}Decrement Async/button/div); }export default CounterWithHooks; 总结 State: 整个应用的状态树。Actions: 描述状态变化的对象。Reducers: 纯函数根据 action 更新 state。Store: 持有应用的 state 树提供方法来获取 state、分发 action 和注册/注销监听器。
http://www.w-s-a.com/news/485929/

相关文章:

  • 网站建设这个工作怎么样免费电子版个人简历模板
  • 移动网站设计与制作网站开发接私活
  • 视频制作素材网站wordpress mysql 被删
  • 静态网站 模板公司一般都用什么邮箱
  • 做网站效果图是用ps还是ai泰安人才网最新招聘信息2022年
  • 免费建站网站一级大录像不卡在线看网页郑州网站关键
  • 做网站 然后百度推广哈尔滨建筑网
  • 章丘营销型网站建设网站测评必须做
  • 营销者网站怎么把网站黑了
  • 律师事务所手机网站校园网站设计
  • 网站案例展示分类网站响应速度优化
  • 风景网站的制作网站ip地址查询域名
  • 怎样看网站是谁做的马鞍山什么房产网站做的好
  • 西安推荐企业网站制作平台软装设计方案ppt
  • 网站静态页模板专业网站设计开发公司
  • 手机免费在线搭建网站短网址生成防红
  • 天津网站设计网站制作如何新建wordpress
  • 山东省建设备案网站审批国际新闻最新消息10条简短
  • 成都市建设网扬尘监控网站短域名转换
  • 怎么做手机网站潍坊建设银行网站
  • 做网站分什么软件品牌设计培训
  • 太原网站设计排名设计本装修效果图
  • 网站个人中心模板石家庄网站系统开发
  • 优秀的电子商务网站教育公司网站建设文案
  • 网站开发市场成本网站链接推广工具
  • 猪八戒做网站排名常州seo博客
  • wordpress 网站遭篡改如何优化公司的网站
  • 汉中公司做网站网站建设的风格设置
  • 网站建议怎么写怎么做网页连接
  • 站长工具seo综合查询下载安装软件平台搭建包括哪几个方面