I am trying to retrieve some data from the server and for some odd reason, componentDidMount()
not starting as it should. I added a console.log()
statement inside componentDidMount()
to check if it was firing. I know that the server request works as it should. I used it without reaction and worked as it should.
class App extends React.Component { constructor(props, context) { super(props, context); this.state = { obj: {} }; }; getAllStarShips () { reachGraphQL('http://localhost:4000/', `{ allStarships(first: 7) { edges { node { id name model costInCredits pilotConnection { edges { node { ...pilotFragment } } } } } } } fragment pilotFragment on Person { name homeworld { name } }`, {}). then((data) => { console.log('getALL:', JSON.stringify(data, null, 2)) this.setState({ obj: data }); }); } componentDidMount() { console.log('Check to see if firing') this.getAllStarShips(); } render() { console.log('state:',JSON.stringify(this.state.obj, null, 2)); return ( <div> <h1>React-Reach!</h1> <p>{this.state.obj.allStarships.edges[1].node.name}</p> </div> ); } } render( <App></App>, document.getElementById('app') );
source share