Skip to content

Commit 806aa3c

Browse files
committed
Returning JSX.Element rather than ReactElement
1 parent 828a2bb commit 806aa3c

File tree

9 files changed

+50
-46
lines changed

9 files changed

+50
-46
lines changed

packages/contentful/src/ContentfulVisual.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ReactElement } from 'react'
21
import ReactVisual from '@react-visual/react'
32
import { ContentfulAsset, ContentfulVisualProps } from './types/contentfulVisualTypes'
43
import {
@@ -17,7 +16,7 @@ import {
1716
// Render a Visual using Contentful data
1817
export default function ContentfulVisual(
1918
props: ContentfulVisualProps
20-
): ReactElement | null {
19+
): JSX.Element | null {
2120

2221
// Destructure some props
2322
const {

packages/next/src/NextVisual.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import _Image from "next/image";
44
const Image = ("default" in _Image ? _Image.default : _Image) as typeof _Image;
55

6-
import type { ReactElement } from 'react'
7-
86
import { makeImagePlaceholder } from './lib/placeholder'
97
import {
108
VisualWrapper,
@@ -17,7 +15,7 @@ import { NextVisualProps } from './types/nextVisualTypes'
1715
// Render a Sanity image via Next/Image
1816
export default function NextVisual(
1917
props: NextVisualProps
20-
): ReactElement | null {
18+
): JSX.Element | null {
2119

2220
// Destructure props
2321
const {
@@ -82,8 +80,15 @@ export default function NextVisual(
8280

8381
// An image rendered within the Visual
8482
function NextImage({
85-
src, sizes, alt, fit, position, priority, loader, placeholderData
86-
}: any): ReactElement {
83+
src,
84+
sizes,
85+
alt,
86+
fit,
87+
position,
88+
priority,
89+
loader,
90+
placeholderData,
91+
}: any): JSX.Element {
8792
return (
8893
<Image
8994
{ ...{ src, sizes, priority, loader, alt } }

packages/react/src/LazyVideo/AccessibilityControls.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import { LazyVideoProps } from '../types/lazyVideoTypes'
2-
import {
3-
CSSProperties,
4-
type ReactElement,
5-
} from 'react';
2+
import type { CSSProperties } from 'react';
63
import { PositionOption } from '../types/reactVisualTypes'
74

85
// How big to make the button. Can't be too small and still be ADA friendly
@@ -33,7 +30,7 @@ export default function AccessibilityControls({
3330
pauseIcon,
3431
hideAccessibilityControls,
3532
accessibilityControlsPosition,
36-
}: AccessibilityControlsProps): ReactElement | null {
33+
}: AccessibilityControlsProps): JSX.Element | null {
3734
// If hidden, return nothing
3835
if (hideAccessibilityControls) return null;
3936

packages/react/src/LazyVideo/LazyVideoClient.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import { useInView } from 'react-intersection-observer'
55
import { useMediaQueries } from '@react-hook/media-query'
6-
import { useEffect, type ReactElement, useRef, useCallback, type MutableRefObject, useState } from 'react'
6+
import { useEffect, useRef, useCallback, type MutableRefObject, useState } from 'react'
77
import type { LazyVideoProps } from '../types/lazyVideoTypes';
88
import { fillStyles, transparentGif } from '../lib/styles'
99
import AccessibilityControls from './AccessibilityControls'
@@ -38,8 +38,7 @@ export default function LazyVideoClient({
3838
pauseIcon,
3939
hideAccessibilityControls,
4040
accessibilityControlsPosition,
41-
}: LazyVideoClientProps): ReactElement {
42-
41+
}: LazyVideoClientProps): JSX.Element {
4342
// Track the actual video playback state. Start in a paused state because
4443
// even with an autoplay video, it won't actually have started playing yet.
4544
const [isVideoPaused, setVideoPaused] = useState(true)
@@ -173,9 +172,9 @@ export default function LazyVideoClient({
173172

174173
// Switch the video asset depending on media queries
175174
function ResponsiveSource({
176-
mediaSrcs, videoRef
177-
}: ResponsiveVideoSourceProps): ReactElement | undefined {
178-
175+
mediaSrcs,
176+
videoRef,
177+
}: ResponsiveVideoSourceProps): JSX.Element {
179178
// Find the src url that is currently active
180179
const { matches } = useMediaQueries(mediaSrcs)
181180
const srcUrl = getFirstMatch(matches)

packages/react/src/LazyVideo/LazyVideoServer.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import type { ReactElement } from 'react'
21
import type { LazyVideoProps } from '../types/lazyVideoTypes'
32
import LazyVideoClient from './LazyVideoClient'
43

54
// This wrapper function exists to take Function props and make them
65
// serializable for the LazyVideoClient component, which is a Next.js style
76
// client component.
8-
export default function LazyVideo(
9-
props: LazyVideoProps
10-
): ReactElement | undefined {
11-
7+
export default function LazyVideo(props: LazyVideoProps): JSX.Element | null {
128
// Destructure some props
139
const {
1410
src,
@@ -32,7 +28,7 @@ export default function LazyVideo(
3228
return [url, media]
3329
})
3430
// If the array ended up empty, abort
35-
if (mediaSrcEntries.filter(([url]) => !!url).length == 0) return
31+
if (mediaSrcEntries.filter(([url]) => !!url).length == 0) return null;
3632

3733
// Make the hash
3834
mediaSrcs = Object.fromEntries(mediaSrcEntries)
@@ -41,7 +37,7 @@ export default function LazyVideo(
4137
} else {
4238
if (videoLoader) srcUrl = videoLoader({ src })
4339
else if (typeof src == 'string') srcUrl = src
44-
if (!srcUrl) return // If no url could be built, abort
40+
if (!srcUrl) return null; // If no url could be built, abort
4541
}
4642

4743
// Render client component

packages/react/src/PictureImage.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ReactElement } from 'react'
21
import type { PictureImageProps } from './types/pictureImageTypes'
32
import type { ImageLoader, SourceMedia, SourceType } from './types/reactVisualTypes'
43
import { deviceSizes, imageSizes } from './lib/sizes'
@@ -14,10 +13,7 @@ type ImageSourceProps = {
1413
media?: SourceMedia
1514
}
1615

17-
export default function PictureImage(
18-
props: PictureImageProps
19-
): ReactElement {
20-
16+
export default function PictureImage(props: PictureImageProps): JSX.Element {
2117
// Destructure props
2218
const {
2319
src,
@@ -94,12 +90,17 @@ function makeSrcUrl(
9490

9591
// Make a source tag with srcset for the provided type and/or media attribute
9692
function Source({
97-
widths, imageLoader, sizes, src, type, media
98-
}: ImageSourceProps): ReactElement {
9993
const srcSet = makeSrcSet(widths, imageLoader, { src, type, media })
10094
return (
10195
<source {...{ type, media, srcSet, sizes }} />
10296
)
97+
widths,
98+
imageLoader,
99+
sizes,
100+
src,
101+
type,
102+
media,
103+
}: ImageSourceProps): JSX.Element {
103104
}
104105

105106
// Make a srcset string from an array of width integers using the imageLoader

packages/react/src/ReactVisual.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { ReactElement } from 'react'
2-
31
import VisualWrapper from './VisualWrapper'
42
import LazyVideo from './LazyVideo'
53
import PictureImage from './PictureImage'
@@ -10,7 +8,7 @@ import { fillStyles } from './lib/styles'
108

119
export default function ReactVisual(
1210
props: ReactVisualProps
13-
): ReactElement | null {
11+
): JSX.Element | null {
1412

1513
// Destructure props
1614
const {

packages/react/src/VisualWrapper.tsx

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { CSSProperties, ReactElement } from 'react'
1+
import type { CSSProperties } from 'react'
22
import { fillStyles, cx } from './lib/styles'
33
import { isNumeric } from './lib/values'
44
import type { VisualWrapperProps } from './types/visualWrapperTypes'
@@ -13,11 +13,18 @@ type MakeResponsiveAspectsProps = Pick<VisualWrapperProps,
1313

1414
// Wraps media elements and applys layout and other functionality
1515
export default function VisualWrapper({
16-
expand, width, height,
17-
aspect, sourceMedia, image, video,
18-
children, className, style, dataAttributes
19-
}: VisualWrapperProps): ReactElement {
20-
16+
expand,
17+
width,
18+
height,
19+
aspect,
20+
sourceMedia,
21+
image,
22+
video,
23+
children,
24+
className,
25+
style,
26+
dataAttributes,
27+
}: VisualWrapperProps): JSX.Element {
2128
// If aspect is a function, invoke it to determine the aspect ratio
2229
let aspectRatio, aspectStyleTag, aspectClasses
2330
if (typeof aspect == 'function' && sourceMedia && sourceMedia.length) {
@@ -51,10 +58,13 @@ export default function VisualWrapper({
5158

5259
// Create a style tag that applies responsive aspect ratio values
5360
function makeResponsiveAspects({
54-
aspectCalculator, sourceMedia, image, video
61+
aspectCalculator,
62+
sourceMedia,
63+
image,
64+
video,
5565
}: MakeResponsiveAspectsProps): {
56-
aspectClasses: string
57-
aspectStyleTag: ReactElement
66+
aspectClasses: string;
67+
aspectStyleTag: JSX.Element;
5868
} {
5969

6070
// Make CSS classes and related rules that are specific to the query and

packages/sanity-next/src/SanityNextVisual.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { ReactElement } from 'react'
21
import NextVisual from '@react-visual/next'
32
import { makeImageUrl, makeFileUrl, makeImageLoader } from './lib/urlBuilding'
43
import {
@@ -11,7 +10,7 @@ import { SanityNextVisualProps } from './types/sanityNextVisualTypes'
1110

1211
export default function SanityNextVisual(
1312
props: SanityNextVisualProps
14-
): ReactElement | null {
13+
): JSX.Element | null {
1514

1615
// Destructure some props
1716
let {

0 commit comments

Comments
 (0)