Skip to content
Advertisement

refactoring Class component to function Component with react-redux

I am trying to refactor a Class component into a Function component in a react-redux app, but I am a bit stuck. When I try to convert this Component to a function Component, this line of code this.props.weather.map(this.renderWeather) no longer executes and it cannot read the list portion of code declared within the variables underneath the renderWeather() function

JavaScript

Advertisement

Answer

So it depends where you want to get the weather data from.

  1. You could pass it as a prop
JavaScript
  1. You could grab it from the Redux Store via useSelector
JavaScript

Note: You don’t have to do the renderWeather inside the map as an anonymous function, it may be simpler to refactor it out to its own WeatherItem component or something.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement