In a functional react component like below, how do you access the props that are sent over from the redux store, similar to how on a class component's this.props
in componentDidMount()
are accessible, shown in the comment below?
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);
The props will be passed as the first argument of the functional component.
const ComponentName = (props) => {
return (
<div>
<div>{ props.something }</div>
</div>
);
};
You can find more details on the official document https://reactjs.org/docs/components-and-props.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.