diff --git a/README.md b/README.md index bc67c66..765e6ea 100644 --- a/README.md +++ b/README.md @@ -8,15 +8,15 @@ ReScript Brazil Community

-> :warning: This repo contains experimental bindings for [@tanstack/query](https://tanstack.com/query/v4) using the experimental optional fields API with ReScript@v10. -If you're looking bindings to the React Query v3 click [here](https://github.com/rescriptbr/react-query/tree/v0.0.2). +> :warning: This repo contains experimental bindings for [@tanstack/query](https://tanstack.com/query/v4) using the new optional fields API. +If you're looking for bindings to the React Query v3 click [here](https://github.com/rescriptbr/react-query/tree/v0.0.2). ## Installation Install the package using npm/yarn: ```sh -yarn add @rescriptbr/react-query react-query +yarn add @rescriptbr/react-query @tanstack/react-query ``` Add the package to `bs-dependencies` in your `bsconfig.json`: @@ -33,9 +33,6 @@ Add the package to `bs-dependencies` in your `bsconfig.json`: ## Basic usage ```rescript -/* -* Local bindings for fetch -*/ module Fetch = { type response @@ -54,18 +51,15 @@ let fetchTodos = (_): Js.Promise.t => { module TodoItem = { @react.component let make = () => { - let queryResult = ReactQuery.useQuery( - ReactQuery.queryOptions( - ~queryFn=fetchTodos, - ~queryKey="todos", - /* - * Helper functions to convert unsupported TypeScript types in ReScript - * Check out the module ReactQuery_Utils.res - */ - ~refetchOnWindowFocus=ReactQuery.refetchOnWindowFocus(#bool(false)), - (), - ), - ) + let queryResult = ReactQuery.useQuery({ + queryFn: fetchTodos, + queryKey: ["todos"], + /* + * Helper functions to convert unsupported TypeScript types in ReScript + * Check out the module ReactQuery_Utils.res + */ + refetchOnWindowFocus: ReactQuery.refetchOnWindowFocus(#bool(false)), + })
{switch queryResult { @@ -86,7 +80,10 @@ let client = ReactQuery.Provider.createClient() @react.component let make = () => { -

{React.string("ReScript + React Query")}

+
+

{React.string("ReScript + React Query")}

+ +
} ``` diff --git a/package.json b/package.json index 887f4b6..521b630 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rescriptbr/react-query", - "version": "1.0.0", + "version": "1.0.1", "main": "index.js", "license": "MIT", "keywoprds": [ diff --git a/src/ReactQuery_Mutation.res b/src/ReactQuery_Mutation.res index 2038f06..4345945 100644 --- a/src/ReactQuery_Mutation.res +++ b/src/ReactQuery_Mutation.res @@ -19,33 +19,29 @@ type mutateParams<'mutationVariables, 'mutationData, 'mutationError, 'unknown> = >, } -@deriving(abstract) type mutationOptions<'mutationVariables, 'mutationData, 'mutationError, 'unknown> = { mutationKey: array, mutationFn: 'mutationVariables => Js.Promise.t<'mutationData>, - @optional onMutate: 'mutationVariables => Js.Promise.t, - @optional - onSuccess: ( + onMutate?: 'mutationVariables => Js.Promise.t, + onSuccess?: ( 'mutationData, 'mutationVariables, Js.Nullable.t, ) => Js.Promise.t<'unknown>, - @optional - onError: ( + onError?: ( 'mutationError, 'mutationVariables, Js.Nullable.t, ) => Js.Promise.t<'unknown>, - @optional - onSettled: ( + onSettled?: ( 'mutationData, 'mutationError, 'mutationVariables, Js.Nullable.t, ) => Js.Promise.t<'unknown>, - @optional retry: ReactQuery_Types.retryValue<'mutationError>, - @optional retryDelay: ReactQuery_Types.retryDelayValue<'mutationError>, - @optional useErrorBoundary: bool, + retry?: ReactQuery_Types.retryValue<'mutationError>, + retryDelay?: ReactQuery_Types.retryDelayValue<'mutationError>, + useErrorBoundary?: bool, } type mutationResult<'mutationVariables, 'mutationData, 'mutationError, 'unknown> = {