Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created June 26, 2022 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/f1a99836fd26b57aab11353ec9cc7fd7 to your computer and use it in GitHub Desktop.
Save geraldodev/f1a99836fd26b57aab11353ec9cc7fd7 to your computer and use it in GitHub Desktop.
react-router-dom useLoaderData example
(ns crudis.ui.routes.countries
(:require
["react-router-dom" :refer [useLoaderData]]
[crudis.util.helix :refer [defnc]]
[helix-window.fixed-size-list :as fsl]
[helix.core :as hx :refer [$ <> fnc]]
[helix.dom :as d :refer [div]]
[paqueta.fetch :as fetch]
[promesa.core :as p]
))
(defn loader
[]
(p/let [resp (fetch/get "/api/countries")]
(if (= (:status resp) 200)
(:body resp)
[])))
(defnc CountriesView
[]
(let [countries (useLoaderData)]
(div
"CountriesView"
($ fsl/FixedSizeList
{:height 150
:witdh 300
:item-data countries
:item-count (count countries)
:item-size 25}
(fnc [{:keys [index style data]
:as p}]
(div {:style style :key index}
(-> (get data index)
:country_name))))
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment