goodsSearch.js 1001 B

123456789101112131415161718192021222324252627282930313233
  1. import {Provider, connect} from 'react-redux';
  2. import {createStore, combineReducers, applyMiddleware, bindActionCreators} from 'redux';
  3. import thunk from 'redux-thunk';
  4. import {actionPromise} from "./index"
  5. import {gql, actionGoods, getData, actionSearch, actionCartAdd} from "../reducers/index";
  6. import { useEffect } from 'react';
  7. import {OneGood, CGoodsList} from "./index";
  8. const mapStateToProps = state => ({
  9. state: state,
  10. search: getData(state, "search", "GoodFind")
  11. });
  12. const mapDispatchToProps = dispatch => bindActionCreators({
  13. getData: actionSearch,
  14. onAdd: actionCartAdd
  15. }, dispatch);
  16. const GoodsSearch = ({search, name, getData, onAdd}) => {
  17. useEffect(() => getData(name), [name])
  18. return(
  19. <>
  20. <div className = "goodsWrapper">
  21. <CGoodsList arr = {search} onAdd = {onAdd}/>
  22. </div>
  23. </>
  24. )
  25. }
  26. const CGoodsSearch = connect(mapStateToProps, mapDispatchToProps)(GoodsSearch);
  27. export default CGoodsSearch;