I am integrating react.js with drupal and I am requesting json file through ajax every 2 seconds which is not best practices so I want to cache the results and I read somewhere that (react.js lacks the ajax capabilities) so how it is possible to cache the results?
2 Answers
You can use WebSockets with React so that you do not have to poll the server (i.e. send repeated ajax requests at a given interval). With React, you normally store the data received from the server in state using the setState method (http://facebook.github.io/react/docs/component-api.html). Then any time the state data is updated, React will diff the DOM and re-render necessary components.
Comments
Do you have any code samples? Are you using any library / framework for your models? I would suggest abstracting network requests out of views into some sort of data model, whether that is Backbone, Angular, Flux Architecture, etc. There you can decide whether you want to poll the data, use WebSockets, or request the data based on a change of state in your view.