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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
Forbes - Security
Forbes - Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Latest news
Latest news
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
Cyberwarzone
Cyberwarzone
Vercel News
Vercel News
V
Vulnerabilities – Threatpost
I
InfoQ
GbyAI
GbyAI
有赞技术团队
有赞技术团队
雷峰网
雷峰网
阮一峰的网络日志
阮一峰的网络日志
A
Arctic Wolf
F
Full Disclosure
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Check Point Blog
Hugging Face - Blog
Hugging Face - Blog
Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
M
MIT News - Artificial intelligence
Engineering at Meta
Engineering at Meta
The Register - Security
The Register - Security
T
Tor Project blog
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
S
Security Affairs
W
WeLiveSecurity
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Stack Overflow Blog
Stack Overflow Blog
Apple Machine Learning Research
Apple Machine Learning Research
H
Heimdal Security Blog
S
Secure Thoughts
Y
Y Combinator Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Latest
Security Latest
Martin Fowler
Martin Fowler
G
Google Developers Blog
宝玉的分享
宝玉的分享
腾讯CDC
TaoSecurity Blog
TaoSecurity Blog
T
Threatpost
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Project Zero
Project Zero
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
MongoDB | Blog
MongoDB | Blog

博客园 - 懒人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
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。