Skip to content

Commit

Permalink
fix(devtools): prevent devtools explorer from collapsing when data is…
Browse files Browse the repository at this point in the history
… being fetched
  • Loading branch information
zorzysty committed Sep 24, 2022
1 parent 650fb99 commit 94cb903
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 17 deletions.
28 changes: 12 additions & 16 deletions packages/react-query-devtools/src/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type Entry = {
}

type RendererProps = {
HandleEntry: HandleEntryComponent
handleEntry: (entry: Entry) => JSX.Element
label?: string
value: unknown
subEntries: Entry[]
Expand Down Expand Up @@ -101,7 +101,7 @@ export function chunkArray<T>(array: T[], size: number): T[][] {
type Renderer = (props: RendererProps) => JSX.Element

export const DefaultRenderer: Renderer = ({
HandleEntry,
handleEntry,
label,
value,
subEntries = [],
Expand All @@ -126,11 +126,7 @@ export const DefaultRenderer: Renderer = ({
</ExpandButton>
{expanded ? (
subEntryPages.length === 1 ? (
<SubEntries>
{subEntries.map((entry) => (
<HandleEntry key={entry.label} entry={entry} />
))}
</SubEntries>
<SubEntries>{subEntries.map(handleEntry)}</SubEntries>
) : (
<SubEntries>
{subEntryPages.map((entries, index) => (
Expand All @@ -149,11 +145,7 @@ export const DefaultRenderer: Renderer = ({
{index * pageSize + pageSize - 1}]
</LabelButton>
{expandedPages.includes(index) ? (
<SubEntries>
{entries.map((entry) => (
<HandleEntry key={entry.label} entry={entry} />
))}
</SubEntries>
<SubEntries>{entries.map(handleEntry)}</SubEntries>
) : null}
</Entry>
</div>
Expand All @@ -171,8 +163,6 @@ export const DefaultRenderer: Renderer = ({
)
}

type HandleEntryComponent = (props: { entry: Entry }) => JSX.Element

type ExplorerProps = Partial<RendererProps> & {
renderer?: Renderer
defaultExpanded?: true | Record<string, boolean>
Expand Down Expand Up @@ -246,8 +236,14 @@ export default function Explorer({
const subEntryPages = chunkArray(subEntries, pageSize)

return renderer({
HandleEntry: ({ entry }) => (
<Explorer value={value} renderer={renderer} {...rest} {...entry} />
handleEntry: (entry) => (
<Explorer
key={entry.label}
value={value}
renderer={renderer}
{...rest}
{...entry}
/>
),
type,
subEntries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Explorer', () => {
pageSize={10}
expanded={false}
subEntryPages={[[{ label: 'A lovely label' }]]}
HandleEntry={() => <></>}
handleEntry={() => <></>}
value={undefined}
subEntries={[]}
type="string"
Expand Down

0 comments on commit 94cb903

Please sign in to comment.