@colisweb/rescript-toolkit 5.20.4 → 5.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "5.20.4",
3
+ "version": "5.21.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -284,3 +284,48 @@ let mutateWithParams = (
284
284
  revalidate,
285
285
  )
286
286
  }
287
+
288
+ module FetchAndRender = {
289
+ @react.component
290
+ let make = (
291
+ type argument response err,
292
+ ~config: module(Config with
293
+ type argument = argument
294
+ and type response = response
295
+ and type error = err
296
+ ),
297
+ ~argument,
298
+ ~children,
299
+ ) => {
300
+ let (data, _, _) = useFetcher(config, Some(argument))
301
+
302
+ children(data)
303
+ }
304
+ }
305
+
306
+ module FetchAndRenderWithSuspense = {
307
+ @react.component
308
+ let make = (
309
+ type argument response err,
310
+ ~config: module(Config with
311
+ type argument = argument
312
+ and type response = response
313
+ and type error = err
314
+ ),
315
+ ~argument,
316
+ ~children,
317
+ ~fallback=?,
318
+ ~fallbackRender,
319
+ ) => {
320
+ <Toolkit.Ui.ErrorBoundary
321
+ fallbackRender={({error}) => {
322
+ let module(C) = config
323
+ let apiError: error<C.error> = error->Obj.magic
324
+ fallbackRender(apiError)
325
+ }}>
326
+ <React.Suspense fallback={fallback->Option.getWithDefault(<Toolkit.Ui.SpinnerFullScreen />)}>
327
+ <FetchAndRender config argument> {data => children(data)} </FetchAndRender>
328
+ </React.Suspense>
329
+ </Toolkit.Ui.ErrorBoundary>
330
+ }
331
+ }