Created
June 26, 2022 12:56
-
-
Save geraldodev/f1a99836fd26b57aab11353ec9cc7fd7 to your computer and use it in GitHub Desktop.
react-router-dom useLoaderData example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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