parse-community / ParseReact

Seamlessly bring Parse data into your React applications.
https://parseplatform.org
Other
1.3k stars 209 forks source link

Can't get objects from Parse #190

Open Tim77277 opened 6 years ago

Tim77277 commented 6 years ago

Hi I tried to use the example code on your README and changed the Parse Class Name to get the desired objects, but it crashes in render function "this.data.ads.map". It gives the message "can not call map of undefined". Does it means that Parse.Query did not get trigger? I have tried to use the Parse JS SDK and got the objects with no issue so I think this issue is not something related to configuration.

import React, { Component } from 'react';
import Parse, {Query} from 'parse';
import ParseReact from 'parse-react';

Parse.initialize('MY_APPLICATION_ID');
Parse.serverURL = 'MY_PARSE_SERVER_URL';

var Advertisements = React.createClass({
  mixins: [ParseReact.Mixin], // Enable query subscriptions

  observe: function() {
    // Subscribe to all Advertisement objects, ordered by creation date
    // The results will be available at this.data.ads
    return {
      ads: (new Parse.Query('Advertisement')).ascending('createdAt')
    };
  },

  render: function() {
    // Render the text of each comment as a list item
    return (
      <ul>
        {this.data.ads.map(function(c) {
          return <li>{c.text}</li>;
        })}
      </ul>
    );
  }
});

class App extends React.Component {
    render() {
      return <div >< Advertisements /></div>
    }
}

export default App;