import {Provider, connect} from 'react-redux';
import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
import thunk from 'redux-thunk';
import {actionPromise} from "./index"
import {gql, actionGoods, getData, actionCartAdd} from "../reducers/";
import { useEffect } from 'react';
import {OneGood, CGoodsList} from "./index";


  
  const mapStateToProps = state => ({
    state: state,
    goods: getData(state, "goods", "GoodFind"),
    status: state.promiseRed && state.promiseRed.goods &&
    state.promiseRed.goods.payload && state.promiseRed.goods &&
    state.promiseRed.goods.status,

  });
  
  const mapDispatchToProps = dispatch => bindActionCreators({
    getData: actionGoods,
    onAdd: actionCartAdd
  }, dispatch);
  


const GoodsCategory = ({goods, id, tittle = "Товари", getData, onAdd}) => {

  useEffect(() =>  getData(id), [id])
  return(
      <>
        
        <div className = "goodsWrapper">
            <CGoodsList arr = {goods} onAdd = {onAdd}/>
        </div>
      </>
  )
}

const CGoodsCategory = connect(mapStateToProps, mapDispatchToProps)(GoodsCategory);




  export default CGoodsCategory;