I am little confuse in the efficient way to use connect()
from react-redux library. I have the blow component
class SignUp extends React.Component {
//some functions
render(){
return (
<SignUpPageWrapper>
<SignUpPage>
<SignUpPageLeft>
<SignUpLeftText /> //component
</SignUpPageLeft>
<SignUpPageRight>
<SignUpForm /> //component <=
</SignUpPageRight>
</SignUpPage>
<SignUpFooter /> //component
</SignUpPageWrapper>
);
}
}
In above code, few are react Component
(//commented) and rest are const
from styled-component library.
As of now, I have made SignUpForm
as a container, i.e wrapped into connect()
class SignUpForm extends React.Component {
//lots of code here using this.props from connect()
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(SignUpForm);
But I feel that this is not the efficient way to use connect
, the better would be to wrap the parent component SignUp
into connect
like below, and then passing the methods
and states
as props
to the child components.
class SignUp extends React.Component {
//some functions
render(){
return (
//other components
<SignUpPageRight>
<SignUpForm signupFunc={this.props.signupFunc} />
</SignUpPageRight>
</SignUpPage>
<SignUpFooter /> //component
</SignUpPageWrapper>
);
}
}
export default connect(
mapStateToProps,
mapDispatchToProps
)(SignUp);
What would be the clean, efficient and good way to write this code?
connect()
parent component, pass down the props and make the children stateless functional components. – Liselisetta