cki*_*ris 1 javascript reactjs redux react-redux
在如下所示的功能性 React 组件中,如何访问从 redux 存储发送过来的 props,类似于如何访问类组件的this.propsin ,如下面的评论所示?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);
Run Code Online (Sandbox Code Playgroud)
props 将作为功能组件的第一个参数传递。
const ComponentName = (props) => {
return (
<div>
<div>{ props.something }</div>
</div>
);
};
Run Code Online (Sandbox Code Playgroud)
您可以在官方文档https://reactjs.org/docs/components-and-props.html上找到更多详细信息
| 归档时间: |
|
| 查看次数: |
2705 次 |
| 最近记录: |