mercredi 4 février 2015

Pass data from callback to React component?


I'm rendering a react component that needs data that returns asynchronously. How should I pass this to the react component when it returns from the callback?


currently in render function:



var dataToReturn;
asynchCall(args, function(err, results) {
dataToReturn = results;
})

return (
<MyComponent data={dataToReturn} />
)


This of course is not working out because the data has not returned yet. If I move the render into the callback, that seems like a bad programming pattern. Is there anything in the React API meant for this use case?


thank you!





Aucun commentaire:

Enregistrer un commentaire