Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinmungai/7d4e93e30c5bbd5cab4f1b19b56c52b2 to your computer and use it in GitHub Desktop.
Save kevinmungai/7d4e93e30c5bbd5cab4f1b19b56c52b2 to your computer and use it in GitHub Desktop.
Using Shadow CLJS with React Native

How to use Shadow CLJS with React Native

This guides does not assume you are using expo. It is not yet perfect, especially the hot reloading part but maybe shadow-cljs could be modified.

  1. Create the React Native Project
react-native init <NameOfYourProject>

yarn add --dev shadow-cljs
  1. Initialize Shadow CLJS

This command will ask to create a shadow-cljs.edn file.

shadow-cljs init
  1. Modify the shadow-cljs.edn file as follows
{:source-paths [...]
 :dependencies [...]
 ...
 :builds
 {:app
  {:target :react-native
   :init-fn <the clojurescript function to be called e.g. AppRegistry>
   :output-dir "<Folder For Your JS OUTPUT>"}}}
  1. Create your src folder for your Clojurescript.

  2. Change the MainApplication.java to the JS output folder. Remember no first slash ahead of the folder name. Note shadow-cljs creates its own index.js file.

    @Override
    protected String getJSMainModuleName() {
      return "app/index";
    }
  1. Change the app level build.gradle to the JS output folder as above.
project.ext.react = [
    entryFile: "app/index.js"

Running the Application

  1. Start Shadow-CLJS
shadow-cljs watch app --this "app" depends on what you called your build
  1. Start react-native
react-native run-android 

Hot Reloading your application

In order to see the changes of your Clojurescript on the phone just type this command every time or create a keyboard macro.

adb shell input text "RR"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment