![](/img/trans.png)
[英]How to access redux-toolkit reducer/action from a class component using react-redux connect()?
[英]In a Functional Component, how do you access props from the redux store using react-redux connect?
在像下面這樣的功能性反應組件中,您如何訪問從 redux 商店發送過來的道具,類似於 class 組件的this.props
在componentDidMount()
中的訪問方式,如下面的評論所示?
import React from 'react';
import { connect } from "react-redux";
import * as actions from "../../actions";
const ComponentName = () => {
// componentDidMount() {
// this.props;
// }
return (
<div>
<div>???</div>
</div>
);
};
function mapStateToProps(state) {
return { state };
}
export default connect(mapStateToProps, actions)(ComponentName);
props 將作為功能組件的第一個參數傳遞。
const ComponentName = (props) => {
return (
<div>
<div>{ props.something }</div>
</div>
);
};
更多細節可以在官方文檔https://reactjs.org/docs/components-and-props.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.