How to convert this code to cljs

i want to use this library react-native-storage in my cljs project, and write the code:

(def storage (new Storage #js {:size 1000
                               :storageBackend js/window.localStorage
                               :defaultExpires (* 1000 3600 24)
                               :enableCache true}))
(.save storage #js {:key :username :data "vinurs"})
(.load storage #js {:key :username})

this is the load function it provided:

// load
    key: 'loginState',

    // autoSync (default: true) means if data is not found or has expired,
    // then invoke the corresponding sync method
    autoSync: true,

    // syncInBackground (default: true) means if data expired,
    // return the outdated data first while invoking the sync method.
    // If syncInBackground is set to false, and there is expired data,
    // it will wait for the new data and return only after the sync completed.
    // (This, of course, is slower)
    syncInBackground: true,

    // you can pass extra params to the sync method
    // see sync example below
    syncParams: {
      extraFetchOptions: {
        // blahblah
      someFlag: true
  .then(ret => {
    // found data go to then()
  .catch(err => {
    // any exception including data not found
    // goes to catch()
    switch ( {
      case 'NotFoundError':
        // TODO;
      case 'ExpiredError':
        // TODO

i don’t know how to convert it to cljs, and load the key’s value in cljs

;; (def storage (new Storage #js {:size 1000
;;                                :storageBackend js/window.localStorage
;;                                :defaultExpires (* 1000 3600 24)
;;                                :enableCache true}))
;; (.save storage #js {:key :username :data "vinurs"})
;; (def ret (.load storage #js {:key :username}))
;; (.then ret #(print %))

it can be get out like this

It’s not clear what part you’re struggling with, but, knowing nothing about react-native-storage, it seems possible that key should be a string, rather than a keyword. Also, if you supply the syncParams option be sure to add a #js before it.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.