Right now I have a generic function that gets all Elements
const mapStateToProps = ({elements}) => {
return {
elements: getElementsByKeyName(elements, 'visibleElements'),
};
};
I'd like to change it to something along the lines of
const mapStateToProps = ({elements}) => {
return {
elements: getElementsById(elements, this.props.elementId),
};
};
If I'm initializing my React class with a required elementId prop, is possible to achieve this rather than getting them all and filtering every time I need to be more specific in my view?
Thanks!
the mapStateToProps function takes the second argument which is own props(props passed to a component outside connect). You can grab the id that way if I correctly understood what you're trying to achieve.
const mapStateToProps = ({elements}, {id}) => {
return {
elements: getElementsById(elements, id),
};
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With