File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import express from 'express' ;
2+ import data from '../src/testData' ;
23
34const router = express . Router ( ) ;
45
5- router . get ( '/' , ( req , res ) => {
6- res . send ( { data : [ ] } ) ;
6+ router . get ( '/contests ' , ( req , res ) => {
7+ res . send ( { contests : data . contests } ) ;
78} ) ;
89
910export default router ;
Original file line number Diff line number Diff line change 2222 },
2323 "homepage" : " ..." ,
2424 "dependencies" : {
25+ "axios" : " ^0.16.2" ,
2526 "ejs" : " ^2.5.6" ,
2627 "express" : " ^4.15.3" ,
2728 "json-loader" : " ^0.5.4" ,
Original file line number Diff line number Diff line change 11import React from 'react' ;
2- import data from '../testData ' ;
2+ import axios from 'axios ' ;
33import Header from './Header' ;
44import ContestPreview from './ContestPreview' ;
55
@@ -9,9 +9,17 @@ class App extends React.Component {
99 contests : [ ]
1010 } ;
1111 componentDidMount ( ) {
12- this . setState ( {
13- contests : data . contests
14- } ) ;
12+ // Make Ajax call and load data response onto the state
13+ axios . get ( '/api/contests' )
14+ . then ( response => {
15+ // console.log(response.data.contests);
16+ this . setState ( {
17+ contests : response . data . contests
18+ } ) ;
19+ } )
20+ . catch ( ( error ) => {
21+ console . log ( error ) ;
22+ } ) ;
1523 }
1624 componentWillUnmount ( ) {
1725 }
You can’t perform that action at this time.
0 commit comments