Answer the question
In order to leave comments, you need to log in
Am I writing redux HOC correctly?
I decided to try to write a redux HOC, but apparently I'm somehow not connecting to the store correctly.
The HOCa code is like this
import React from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
const ProductsAndCustomers = Component => (
class extends React.Component {
// методы
render() {
return <Component/>;
}
}
)
const mapStateToProps = state => {
return {
ProductsAndCustomers: state
}
}
const mapDispatchToProps = dispatch => {
return {
onRequestProducts: () => dispatch()
};
}
// export default connect(
// mapStateToProps,
// mapDispatchToProps,
// )(ProductsAndCustomers);
// Пробовал таким образом, но видимо из-за того, что ProductsAndCustomer, не class, он ругается
const composeProductsAndCustomers = compose(
connect(mapDispatchToProps, mapStateToProps),
ProductsAndCustomers
);
export default composeProductsAndCustomers;
Answer the question
In order to leave comments, you need to log in
const withProductsAndCustomers = Component => {
class ProductsAndCustomers extends React.Component {
// методы
render() {
return <Component {...this.props}/>;
}
}
return connect(mapStateToProps, mapDispatchToProps)(ProductsAndCustomers);
}
const mapStateToProps = state => {
return {
ProductsAndCustomers: state
}
}
const mapDispatchToProps = dispatch => {
return {
onRequestProducts: () => dispatch()
};
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question