I've been working on persistence with a few React apps and noticed that several online examples just use $.ajax() to make calls to the server–commonly in componentDidMount(). Is there a better way to do this?
Example of tutorials that do this:
React Docs: facebook.github.io/react/tips/initial-ajax.html
Amazing React tutorial (shout out to Sahat), within Actions in a FLUX implementation: sahatyalkabov.com/create-a-character-voting-app-u…
Yes, it's called the Fetch API coming to a browser near you. Right now you have to use a polyfill for the spec but I'd get used to using it now. On the last several projects I've contributed to we have gotten along just fine without using jQuery as a dependency.
Well, if it is in React Documentation, it is probably the preferred way to do it.
屈铭
Front-end Developer
@gskema +1 I also recommend axios with React, cause It's api is vary easy to use. For example, you can directly use
.then()to get the response and use.catch()to get the error info incomponentDidMount()