0

I have a connected React component pulling into props from Redux state.

It is getting an array of objects called plots, like this:

function mapStateToProps(state) { return { plots: state.plots.plots }; } 

I want to map some properties of plots into arrays.

Making this call inside the render method works fine:

render() { if (this.props.plots) { console.log(this.props.plots.map(a => a.variety)); }... } 

Defining this method outside the class declaration and calling it inside the render method returns undefined:

const varieties = props => { if (props.plots) { props.plots.map(a => a.variety); } }; render() { if (this.props.plots) { console.log(varieties(this.props); } } 

Anyone know what I'm missing?

1 Answer 1

1

Easy fix.

You are missing a return statement.

const varieties = props => { if (props.plots) { return props.plots.map(a => a.variety); } }; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.