Image
The Image component enables content editors to upload/select and modify images.
Required properties:
propName: the name of the propsource: prop value. It is strictly required only for RSC, but we recommend always providing it for Server Components compatibility.
Other frequently used props:
Section titled “Other frequently used props:”aspectRatio: forces editors to crop an image with a fixed aspect ratio (e.g.16 : 9)alt: fallback alternate text, used if editors don’t provide ALT text via the interfacemaxWidth: instructs React Bricks image optimization on the maximum displayed size for this imagequality: sets the image compression quality (default 80)sizes: provides fine-tuned image direction via the “sizes” attributeimageClassName: class name applied to the rendered image
Usage example
Section titled “Usage example”import { types, Image } from 'react-bricks/frontend'
interface MyBrickProps { image: types.IImageSource}
const MyBrick: types.Brick<MyBrickProps> = ({ image }) => ( ... <Image propName="image" source={image} alt="Product" maxWidth="650" aspectRatio="1.33" /> ...)
MyBrick.schema = { ... }
export default MyBrickRendering
Section titled “Rendering”- On the frontend, the
Imagecomponent displays a responsive, optimized image with progressive loading (lazy load). - In the Admin interface, it allows editors to replace an image by opening a modal where they can:
- Replace an image from the media library, Unsplash, upload, or URL
- Apply transformations (crop, rotate, flip)
- Set the alternate text (ALT), SEO-friendly name (for the image URL), and priority for images above the fold
Optimization
Section titled “Optimization”To boost performance and SEO, upon upload, React Bricks will:
- Create responsive optimized images
- Create the srcSet for optimal image selection on the frontend
- Create a lightweight blurred placeholder for progressive loading when the native lazy loading is unavailable
- Serve images from a global CDN
- Enforce SEO-friendly name via proper rewrite rules
Readonly
Section titled “Readonly”To render an image loaded in React Bricks as read-only, add the readonly flag.
A common use case is rendering blog post thumbnails in a list of posts loaded via the fetchPages function. You can render a thumbnail for each post using <Image readonly source={...}>.
Bind to Meta data or Custom fields
Section titled “Bind to Meta data or Custom fields”As for Text and RichText, you can also bind an image to a page’s custom field or meta image by replacing propName with customFieldName or metaFieldName.
This creates a two-way data binding between the visual editing component and the images set via sidebar controls in the “Page” tab.
Properties
Section titled “Properties”Here’s the Typescript interface for the props of the Image component:
// For both editable and readonly imagesinterface SharedImageProps { readonly?: boolean source?: types.IImageSource alt: string noLazyLoad?: boolean imageClassName?: string imageStyle?: React.CSSProperties quality?: number sizes?: string loading?: 'lazy' | 'eager' renderWrapper?: ({ children: React.ReactNode width?: number height?: number }) => React.ReactElement useNativeLazyLoading?: boolean useWebP?: boolean placeholder?: (props: { aspectRatio?: number maxWidth?: number isDarkColorMode?: boolean isAdmin: boolean }) => string}
// For editable imagesinterface EditableImage extends SharedImageProps { readonly?: false propName?: string metaFieldName?: 'image' customFieldName?: string aspectRatio?: number maxWidth?: number}
// For readonly imagesinterface ReadOnlyImage extends SharedImageProps { readonly: true source: types.IImageSource}
/** * Props for Image */type ImageProps = EditableImage | ReadOnlyImageProperties definition
Section titled “Properties definition”Usage with Server Components
Section titled “Usage with Server Components”When working with Server Components, you need to import from 'react-bricks/rsc':
import { types, Image } from 'react-bricks/rsc'