From 3e3da5ab50ef3cd6917c7aa26ccc50d39bb96a05 Mon Sep 17 00:00:00 2001 From: jrea Date: Wed, 17 Aug 2022 14:13:12 -0400 Subject: [PATCH] feat(react): allow a custom react-query queryclient --- packages/react/README.md | 18 +++++++++++++++++- packages/react/src/context/index.tsx | 22 +++++----------------- packages/react/src/context/types.ts | 2 ++ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/react/README.md b/packages/react/README.md index c7bc71c2..eb9bd689 100644 --- a/packages/react/README.md +++ b/packages/react/README.md @@ -21,7 +21,23 @@ function App() { } ``` -Once added, there is a hook and components available for use. +Once added, there is a hook and components available for use. It is recommended to place the `` as high up in your render tree as possible, since it contains both stying and request wrappers. + +### Included libraries + +Out of the box, [react-query](https://react-query.tanstack.com/) and [mui joy](https://mui.com/joy-ui/getting-started/overview/) is available for use. No set up is required, simply add the dependencies to your code, then use components and functions provided by those libraries. + +They can be customize as follows: + +```typescript +function App() { + return ( + +
Welcome to my great app
+
+ ); +} +``` ### useNile diff --git a/packages/react/src/context/index.tsx b/packages/react/src/context/index.tsx index f4b79693..23d3a52f 100644 --- a/packages/react/src/context/index.tsx +++ b/packages/react/src/context/index.tsx @@ -1,25 +1,23 @@ // eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-nocheck import React, { useMemo, createContext, useContext } from 'react'; import Nile, { NileApi } from '@theniledev/js'; import { CssVarsProvider } from '@mui/joy/styles'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; -import theme from './themeJoiner'; +import defaultTheme from './themeJoiner'; import { NileContext, NileProviderProps } from './types'; -const queryClient = new QueryClient(); +const defaultQueryClient = new QueryClient(); const defaultContext: NileContext = { instance: Nile({ basePath: '', workspace: 'none', credentials: 'include' }), - workspace: '', }; const context = createContext(defaultContext); const { Provider } = context; export const NileProvider = (props: NileProviderProps) => { - const { children } = props; + const { children, theme, queryClient } = props; const values = useMemo(() => { return { @@ -31,19 +29,9 @@ export const NileProvider = (props: NileProviderProps) => { }; }, [props.basePath, props.workspace]); - if (props.theme) { - return ( - - - {children} - - - ); - } - return ( - - + + {children} diff --git a/packages/react/src/context/types.ts b/packages/react/src/context/types.ts index c824630f..e709a359 100644 --- a/packages/react/src/context/types.ts +++ b/packages/react/src/context/types.ts @@ -1,6 +1,7 @@ import { NileApi } from '@theniledev/js'; import React from 'react'; import { Theme } from '@mui/joy/styles'; +import { QueryClient } from '@tanstack/react-query'; export interface NileContext { instance: NileApi; @@ -12,4 +13,5 @@ export interface NileProviderProps { basePath: string; workspace?: string; theme?: Theme; + queryClient?: QueryClient; }