惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
C
CXSECURITY Database RSS Feed - CXSecurity.com
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
T
Tor Project blog
C
Cisco Blogs
G
GRAHAM CLULEY
S
Schneier on Security
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
MongoDB | Blog
MongoDB | Blog
爱范儿
爱范儿
S
SegmentFault 最新的问题
S
Security Affairs
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
J
Java Code Geeks
美团技术团队
Hacker News - Newest:
Hacker News - Newest: "LLM"
U
Unit 42
Latest news
Latest news
T
Tailwind CSS Blog
GbyAI
GbyAI
月光博客
月光博客
PCI Perspectives
PCI Perspectives
Attack and Defense Labs
Attack and Defense Labs
Forbes - Security
Forbes - Security
S
Securelist
AI
AI
Recent Announcements
Recent Announcements
C
Check Point Blog
I
Intezer
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
NISL@THU
NISL@THU
Hacker News: Ask HN
Hacker News: Ask HN
O
OpenAI News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Project Zero
Project Zero
V2EX - 技术
V2EX - 技术
Y
Y Combinator Blog
博客园 - 【当耐特】
aimingoo的专栏
aimingoo的专栏
F
Full Disclosure
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Register - Security
The Register - Security
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News

博客园 - 懒人ABC

Docker 国内镜像源加速列表(转载,真实可用)-https://zhuanlan.zhihu.com/p/1914353637645345944 windows10操作系统下安装facefusion实现视频换脸(windows server不支持哈) 用spark3.5.2+scala2.13.11+JDK17统计文件单词词频 DeepSeek与Elasticsearch结合,可以通过AI模型增强搜索、分析和自动化能力,实现更智能的数据处理(含订单备货和库存预警案例) 配置navicat客户端通过ssl连接windows server 2025的sqlserver2022数据库服务器 在debain下安装思源黑体(Source Han Sans)的注意点 PHP处理建行数币支付的几种情况 windows10下编译php扩展 获取工作表的名称 获取名称管理器里名称应用的所有单元格 spreadsheet 获取名称管理器 sftp配置多个用户权限的问题 十三、Vue中的computed属性 十一、微信小程序-var、let、const用法详解 十、es6之扩展运算符 三个点(...) 九、小程序 Redux详解与在小程序中怎么使用(action和reducers) 八、wepy代码规范 七、Flex 布局 六、页面跳转和路由
十二、react-reudx之@connect 摆脱redux的繁琐操作
懒人ABC · 2019-11-23 · via 博客园 - 懒人ABC
如果对redux的概念和用法掌握的已经不错了 那么现在react-redux会让你的操作更加的得心印手

    忘记subscribe,记住reducer,action和dispatch即可
    React-redux提供Provider和connect两个接口来链接

这里我们还是用一个计数器来讲解

  • 第一步安装
 $  npm install react-redux --save
  • React-redux具体使用
    Provider组件在应用最外层,传入store即可,只用一次
    index.js


import React from 'react';
import ReactDom from 'react-dom';
import App from './App'

Connect负责从外部获取组件需要的参数
App.js




import React from 'react';
import { connect } from 'react-redux'
import {add_A,rem_R,addAsync} from './index.redux.js'
 class App extends React.Component{
    constructor(props){
        super()
    }
    render(){
        return (
            <div>
                <h1>现在是数字几{this.props.num}</h1>
                {

这份代码是actionCreator和reducer 主要改变的代码都在
index.reduer.js





//创建常量
const ADD_N = "加"
const REM_N = "减"

如果上面的基础用法你已经学会了那么再看看下面@connect注解的方法吧

使用装饰器优化connect代码

1、弹出个性化配置(因为很多的配置被react的脚手架隐藏了起来 这一步就是了展开,这个操作是不可逆的)

 $ Npm run eject

2、安装依赖的插件

$ npm install babel-plugin-transform-decorators-legacy插件

3、完成上一步操作在Package.json里babel加上plugins配置 "plugins":["transform-decorators-legacy"]

  "babel": {
    "presets": [
      "react-app"
    ],
    "plugins":["transform-decorators-legacy"]   
  },

上面的步骤都完成了话就可以用@connect注解的方法来优化我们的App.js啦
App.js

import React from 'react';
import { connect } from 'react-redux'
import {add_A,rem_R,addAsync} from './index.redux.js'


作者:吴佳浩
链接:https://www.jianshu.com/p/269473787332
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。