25 lines
684 B
JavaScript
25 lines
684 B
JavaScript
import { useEffect } from "react";
|
|
import { connect } from "react-redux";
|
|
import { loadRestaurants } from '../store/restaurants/actions';
|
|
|
|
export function RestaurantList({ loadRestaurants, restaurants }) {
|
|
useEffect(() =>
|
|
{
|
|
loadRestaurants();
|
|
}, [loadRestaurants]);
|
|
return (
|
|
<ul>
|
|
{restaurants.map(restaurant =>
|
|
(
|
|
<li key={restaurant.id}>{restaurant.name}</li>
|
|
))}
|
|
</ul>
|
|
);
|
|
};
|
|
|
|
const mapStateToProps = state => ({
|
|
restaurants: state.restaurants.records,
|
|
});
|
|
const mapDispatchToProps = {loadRestaurants};
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(RestaurantList); |