Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. import React from 'react';
  2. import ReactDOM from 'react-dom';
  3. import { Provider } from 'react-redux'
  4. import store from './components/store/store'
  5. import App from './App';
  6. import * as serviceWorker from './serviceWorker';
  7.  
  8. ReactDOM.render(
  9. <Provider store={store()}>
  10. <App />
  11. </Provider>,
  12. document.getElementById('root')
  13. );
  14.  
  15. serviceWorker.unregister();
  16.  
  17. import React, { Component } from 'react'
  18. import { connect } from 'react-redux'
  19. import { BrowserRouter as Router, Route } from 'react-router-dom'
  20. import { addDataAction } from './components/actions/addDataAction'
  21.  
  22. etc...
  23.  
  24. class App extends Component {
  25. render() {
  26. return (
  27. <Router>
  28. <div className="App">
  29. <div className="wrapper">
  30. <Header />
  31. <main>
  32. {console.log(this.props.data.tshirts)} <-- empty object?
  33. </main>
  34. </div>
  35. <Footer />
  36. </div>
  37. </Router>
  38. )
  39. }
  40. }
  41.  
  42. const mapStateToProps = state => ({
  43. ...state
  44. })
  45.  
  46. const mapDispatchToProps = dispatch => ({
  47. addDataAction: () => dispatch(addDataAction)
  48. })
  49.  
  50. export default connect(mapStateToProps, mapDispatchToProps)(App);
  51.  
  52. import clothesData from '../json/clothes.data.json'
  53.  
  54. export const addDataAction = {
  55. type: 'ADD_JSON_DATA',
  56. data: clothesData
  57. }
  58.  
  59. export default (state, action) => {
  60. switch (action.type) {
  61. case 'ADD_JSON_DATA':
  62. return {
  63. data: action.data
  64. };
  65. default:
  66. return state;
  67. }
  68. }
  69.  
  70. import { createStore } from "redux"
  71. import addDataReducer from "../reducers/addDataReducer"
  72.  
  73. function store( state = { data: {} } ) {
  74. return createStore(addDataReducer, state)
  75. }
  76.  
  77. export default store
  78.  
  79. "dependencies": {
  80. "gulp": "^4.0.0",
  81. "gulp-sass": "^4.0.2",
  82. "gulp-util": "^3.0.8",
  83. "react": "^16.8.6",
  84. "react-dom": "^16.8.6",
  85. "react-redux": "^7.0.2",
  86. "react-router-dom": "^5.0.0",
  87. "react-scripts": "2.1.8",
  88. "redux": "^4.0.1",
  89. "redux-devtools": "^3.5.0"
  90. }
  91.  
  92. {
  93. "tshirts" : [
  94. {
  95. "id": 707860,
  96. "brand": "H&M",
  97. "name": "T-Shirt",
  98. "photo": "tshirt.jpg",
  99. "colors": [
  100. "red",
  101. "blue",
  102. "green",
  103. "gray"
  104. ],
  105. "sizes": [
  106. "S",
  107. "M",
  108. "L",
  109. "XL"
  110. ],
  111. "price": 14,
  112. "currency": "GBP"
  113. },
  114. {
  115. "id": 43455,
  116. "brand": "Topman",
  117. "name": "The Tee Shirt",
  118. "photo": "tshirt.jpg",
  119. "colors": [
  120. "red",
  121. "blue",
  122. "green",
  123. "gray"
  124. ],
  125. "sizes": [
  126. "S",
  127. "M",
  128. "L",
  129. "XL"
  130. ],
  131. "price": 14,
  132. "currency": "GBP"
  133. }
  134. ],
  135. "jumpers" : [
  136. {
  137. "id": 653655,
  138. "brand": "H&M",
  139. "name": "The J Jumper",
  140. "photo": "jumper.jpg",
  141. "colors": [
  142. "red",
  143. "blue",
  144. "green",
  145. "gray"
  146. ],
  147. "sizes": [
  148. "S",
  149. "M",
  150. "L",
  151. "XL"
  152. ],
  153. "price": 24,
  154. "currency": "GBP"
  155. },
  156. {
  157. "id": 43455,
  158. "brand": "Topman",
  159. "name": "Une Jupe",
  160. "photo": "jumper.jpg",
  161. "colors": [
  162. "red",
  163. "blue",
  164. "green",
  165. "gray"
  166. ],
  167. "sizes": [
  168. "S",
  169. "M",
  170. "L",
  171. "XL"
  172. ],
  173. "price": 23,
  174. "currency": "GBP"
  175. }
  176. ],
  177. "trousers" : [
  178. {
  179. "id": 645645,
  180. "brand": "Next",
  181. "name": "The Trow Sir",
  182. "photo": "trousers.jpg",
  183. "colors": [
  184. "red",
  185. "blue",
  186. "green",
  187. "gray"
  188. ],
  189. "sizes": [
  190. "S",
  191. "M",
  192. "L",
  193. "XL"
  194. ],
  195. "price": 24,
  196. "currency": "GBP"
  197. },
  198. {
  199. "id": 54555,
  200. "brand": "Topman",
  201. "name": "Une Trow",
  202. "photo": "trousers.jpg",
  203. "colors": [
  204. "red",
  205. "blue",
  206. "green",
  207. "gray"
  208. ],
  209. "sizes": [
  210. "S",
  211. "M",
  212. "L",
  213. "XL"
  214. ],
  215. "price": 23,
  216. "currency": "GBP"
  217. }
  218. ],
  219. "jackets" : [
  220. {
  221. "id": 44344,
  222. "brand": "Gap",
  223. "name": "Gap Jacket",
  224. "photo": "jacket.jpg",
  225. "colors": [
  226. "red",
  227. "blue",
  228. "green",
  229. "gray"
  230. ],
  231. "sizes": [
  232. "S",
  233. "M",
  234. "L",
  235. "XL"
  236. ],
  237. "price": 24,
  238. "currency": "GBP"
  239. },
  240. {
  241. "id": 422542,
  242. "brand": "Gap",
  243. "name": "Their other jacket",
  244. "photo": "jacket.jpg",
  245. "colors": [
  246. "red",
  247. "blue",
  248. "green",
  249. "gray"
  250. ],
  251. "sizes": [
  252. "S",
  253. "M",
  254. "L",
  255. "XL"
  256. ],
  257. "price": 23,
  258. "currency": "GBP"
  259. }
  260. ],
  261. "suits" : [
  262. {
  263. "id": 44344,
  264. "brand": "Moss Bros",
  265. "name": "The Three Piece",
  266. "photo": "suit.jpeg",
  267. "colors": [
  268. "red",
  269. "blue",
  270. "green",
  271. "gray"
  272. ],
  273. "sizes": [
  274. "S",
  275. "M",
  276. "L",
  277. "XL"
  278. ],
  279. "price": 24,
  280. "currency": "GBP"
  281. },
  282. {
  283. "id": 422542,
  284. "brand": "Gap",
  285. "name": "The Two Piece",
  286. "photo": "suit.jpeg",
  287. "colors": [
  288. "red",
  289. "blue",
  290. "green",
  291. "gray"
  292. ],
  293. "sizes": [
  294. "S",
  295. "M",
  296. "L",
  297. "XL"
  298. ],
  299. "price": 23,
  300. "currency": "GBP"
  301. }
  302. ]
  303. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement