applyMiddleware(thunkMiddleware)(createStore)(reducers)连续3个括号什么意思?

redux创建store

第一种:

const store = createStore(reducers, applyMiddleware(thunkMiddleware));

第二种:

const store = applyMiddleware(thunkMiddleware)(createStore)(reducers);

两种写法达成的效果一样。

第一种很好理解,第二种看不明白,有没有大佬解释一下?

Heymanfk
浏览 1475回答 1
1回答

慕设计2395807

DZUJFSOOEKBNGDAJTPSILEDVJPSVEUHXDRAZPCSBLYXKUQZGIFRURUDFYUKNNSPCYOXNCJLYUKQGDIYBEUJCCFVRHXZGZVXUXQQUDVRNKJTJJPZVOBMIFRHYXSHNDWJFSRDKPIOHNNJFKKHZEXQGWLIYKXAVHUUANZWWZRLXHSYLRREQHZZFTWILVLYNFELJPZIFBYEIQQAGMCFNTVUSEKHTPIPLOGCDXJZZFCSUVAAKGGZWCZEQMTXATMDTPUKJGCISIOPVCLKADDIVFCPBKZGFSSFYPVLUAQMMPCHYKBNGJZVBKKROFIRQTAGPMMSKAMIYRBNCCFFLTZZPLKXENWLYTSFSBBNEQVHOSFOEBXEOYEKKTPJMYBEHMTPPLURXOPEDNADQSZFSSFEKNAZMSKDXTSIUHTYUURIETKZQNGNWQDMVLHAXWPHEJOAXMGPLVVLTCBZXMKYUQFLOEUTNQMWPSJRXFBOKKNTZAMBIOANMDJCKMSYUHXUKXOIUNUDMWJWCFCLNDGWVOLREMJYYEBHQKKQOAGCPCXXKQNPUXNQDZLIHRUGWCMYHRHXTQSSSBYXDDTXGVKRXAJLBVINQPVLREDKAJPSRNKQGCCSYTCEUWGWYBRNRSUXHQMUENINIROKNPDZJYAPJSCYAWTWSJFOXTWFODNDNCLOVLAQTWSRUQWMPFLROZRTZPVRKADAJILSIXTDLILUUWFIEAJFPRUBAWMPPOVRHEWFLTDCIIVVXBRDJPIPVKAIPEMXHUPFVRAUCFXTISVKOKASFFJPCDSLXSETBKTYJFORHHNADSAAQKGDDJXYFSFGGZGWQLZEYFJOTIULQGNCITWGBJZXNQDADJFEUJNQHXJSKSHJFPEHKTCYV

stone310

不知道是否已经解决这个问题调用方式:`createStroe(reducer,preloadedState,enhancer)` 其中`applyMiddleware(...middlewares)`也就是参数enhancer,在createStore源码里,当enhancer有值时,调用方式如下:    `enhancer(createStore)(reducer, preloadedState)`,也就变成了:    `applyMiddleware(...middlewares)(createStore)(reducer,preloadedState)` 
打开App,查看更多内容
随时随地看视频慕课网APP