Once you’ve grokked the Re-Frame philosophy for building truly reactive applications on React in ClojureScript, you will want to apply it everywhere. One obvious and ubiquitous application of effects is asynchronous HTTP requests, and of course there is an officially sanctioned library for handling these. One problem: it relies on an AJAX library that only works with the browser XHR implementation. So what can we do in React Native-based Clojurescript apps?
It’s actually very simple, and can be accomplished in about ten lines of code.
We’ll rely on cljs-http, a
core.async-based HTTP library.
opts param here is a map that will handle everything that
takes as input, like
:multipart-params. That documentation
can be found in the
Here’s an example of how you might use it:
You’ll want to have registered the
before using them, of course.
Hopefully this small event function has been helpful. It’s short enough that I
don’t think it rises to the level of being a library instead of a blog post, and
in fact I think most people will want to customize which keys they want to
handle. I personally have replaced
opts with just
as those are all I use. Feel free to reach out
over twitter or in
Clojurians Slack with questions.