Skip to content

Commit c4c90b3

Browse files
committed
2 parents 6f7d8aa + ba81870 commit c4c90b3

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/devtools/Explorer.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22

3-
import { styled } from './utils'
3+
import { displayValue, styled } from './utils'
44

55
export const Entry = styled('div', {
66
fontFamily: 'Menlo, monospace',
@@ -154,10 +154,7 @@ export const DefaultRenderer: Renderer = ({
154154
</>
155155
) : (
156156
<>
157-
<Label>{label}:</Label>{' '}
158-
<Value>
159-
{JSON.stringify(value, Object.getOwnPropertyNames(Object(value)))}
160-
</Value>
157+
<Label>{label}:</Label> <Value>{displayValue(value)}</Value>
161158
</>
162159
)}
163160
</Entry>

src/devtools/tests/Explorer.test.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react'
22
import { fireEvent, render, screen } from '@testing-library/react'
33

44
import { chunkArray, DefaultRenderer } from '../Explorer'
5+
import { displayValue } from '../utils'
56

67
describe('Explorer', () => {
78
describe('chunkArray', () => {
@@ -54,4 +55,14 @@ describe('Explorer', () => {
5455
expect(toggleExpanded).toHaveBeenCalledTimes(1)
5556
})
5657
})
58+
59+
describe('displayValue', () => {
60+
it('when the value is a boolean', () => {
61+
expect(displayValue(true)).toBe('true')
62+
})
63+
64+
it('when the value is a BigInt', () => {
65+
expect(displayValue(BigInt(1))).toBe('"1n"')
66+
})
67+
})
5768
})

src/devtools/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,17 @@ export function useSafeState<T>(initialState: T): [T, (value: T) => void] {
123123
return [state, safeSetState]
124124
}
125125

126+
/**
127+
* Displays a string regardless the type of the data
128+
* @param {unknown} value Value to be stringified
129+
*/
130+
export const displayValue = (value: unknown) => {
131+
const name = Object.getOwnPropertyNames(Object(value))
132+
const newValue = typeof value === 'bigint' ? `${value.toString()}n` : value
133+
134+
return JSON.stringify(newValue, name)
135+
}
136+
126137
/**
127138
* Schedules a microtask.
128139
* This can be useful to schedule state updates after rendering.

0 commit comments

Comments
 (0)