I am new to react, and I noticed 2 ways that components built, and wanted to know which to use when
this is the first type, seems like the logical one that I would always use
import React, { Component } from "react";
import { connect } from "react-redux";
class ConnectedForm extends Component {
constructor() {
super();
this.state = {};
}
render() {
return (
<form>
<div> blah blah</div>
</form>
);
}
}
const Form = connect()(ConnectedForm);
export default Form;
but then there is this simple looking component with no class and it's not extending the component:
import React from "react";
import { connect } from "react-redux";
const mapStateToProps = state => {
return state.locations;
};
const LocationsList = ({ locations }) => (
<ul>
{
locations.map(el => (
<li key={el.id}>
Name - {el.name}, Address - {el.address}, Coordinates - {el.coordinates}, Category - {el.category}
</li>
)) }
</ul>
);
const List = connect(mapStateToProps)(LocationsList);
export default List;
I was wondering whats the name of each approach, and when I should prefer the simpler one over the class one?