React - Redux connect()() 语法清晰 [英] React - Redux connect()() syntax clarity

查看:46
本文介绍了React - Redux connect()() 语法清晰的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始学习 react-redux,对 redux 的 connect 函数中指定的语法感到困惑.

I have just started to learn react-redux and got confused with syntax specified in connect function of redux.

根据我的理解,我们定义和调用的普通函数如下:

From my understanding the normal function we define and call as follows:

//function definition
function fun_name(arg){
    //do some operations
}


// function calling
fun_name('my_argument');

在反应中发现了一些有趣的线

In react found some interesting line

export default connect(mapStateToProps, mapDispatchToProps)('SomeComponentName');

但是这里上面的行调用带有两个参数 mapStateToProps,mapDispatchToProps 的连接函数.后者定义了 ('SomeComponentName')

But here the above line calling connect function with two arguments mapStateToProps,mapDispatchToProps. And latter it defined ('SomeComponentName')

有谁知道connect()()"是什么语法或者是export的一部分吗?

推荐答案

在JS中叫做currying.

柯里化是一种函数转换,它将函数从可调用的 f(a, b, c) 转换为可调用的 f(a)(b)(c).

Currying is a transformation of functions that translates a function from callable as f(a, b, c) into callable as f(a)(b)(c).

柯里化不会调用函数.它只是改变了它.

Currying doesn’t call a function. It just transforms it.

来源 https://javascript.info/currying-partials

例如

function outer(){
  return inner
}

function inner(){
 console.log("I got called")
}

outer()()

这篇关于React - Redux connect()() 语法清晰的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆