Skip to content

Instantly share code, notes, and snippets.

@alexlecco
Created July 15, 2020 04:15
Show Gist options
  • Save alexlecco/a4bf4ed9ee53af90121a92a72764d552 to your computer and use it in GitHub Desktop.
Save alexlecco/a4bf4ed9ee53af90121a92a72764d552 to your computer and use it in GitHub Desktop.
fix gyms fetching action
import React from 'react';
import { Link } from 'react-router-dom'
import {connect} from 'react-redux'
import ItemCard from './ItemCard'
import {showGyms} from '../../actions/index'
const CardContent = (props) => {
//eliminamos el useEffect, porque ya consultamos los gyms al principio de la app
return (
<main class="main-content" id="Gimnasios">
<Link to="/profile1">
<div className="container-fluid photos">
<div className="row align-items-stretch">
{props.gyms.map((data) => {
return <ItemCard
img={data.img}
alt={data.alt}
title={data.title}
description={data.description}
adress={data.adress}
size={data.size}
id={data._id}
/>
})}
</div>
</div>
</Link>
</main>
)
}
const mapStateToProps = state => {
return {gyms: state.gym.gyms}
}
const GymsList = connect(mapStateToProps, {showGyms})(CardContent)
export default GymsList
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Provider} from 'react-redux'
import store from './store/index'
import { showGyms } from './actions/index'
//al principio de la app consultamos los gyms
store.dispatch(showGyms())
ReactDOM.render(
<Provider store ={store}>
<App />
</Provider>,
document.getElementById('root')
);
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
import { createStore, applyMiddleware, compose } from 'redux'
import thunk from 'redux-thunk'
import rootReducer from '../reducers/index'
//hacemos esto para poder conectar correctamente la consola de REDUX con la app y podemos ver las actions que se disparan
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
const store = createStore(
rootReducer,
composeEnhancer(applyMiddleware(thunk))
)
export default store
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment