Last active
September 3, 2015 17:33
-
-
Save brunoskonrad/1e8880751011c30d187b to your computer and use it in GitHub Desktop.
Snippet de uso do React com o Parse (http://blog.parse.com/learn/parse-and-react-shared-chemistry/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react'); | |
var Parse = require('parse').Parse; | |
var ParseReact = require('parse-react'); | |
// Inicia o Parse com as credenciais da tua app | |
Parse.initialize('foo', 'bar'); | |
var App = React.createClass({ | |
mixins: [ParseReact.Mixin], | |
observe: function() { | |
return { | |
// Consulta os dados na nuvem e pá | |
tests: (new Parse.Query('TestObject')).ascending('createdAt') | |
}; | |
}, | |
componentDidMount: function() { | |
// Cria um novo registro | |
ParseReact.Mutation.Create('TestObject', {foo: 'bar'}).dispatch(); | |
}, | |
render() { | |
return ( | |
<div> | |
<h1>{this.props.title || 'Hello World'}</h1> | |
// Acessa os dados do parse no `this.data` | |
<p>{this.data.tests.length}</p> | |
</div> | |
); | |
} | |
}); | |
React.render(<App title="Foobar"/>, | |
document.querySelector('[data-app]')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment