Add a GIF picker to React
Connect GIF search to your own composer with a typed selection callback, simple state, and a theme that fits your app.
1. Install and import the styles
Add the package to your React project and import @rowix/gifsnap-react/styles.css once. The stylesheet is scoped to the picker. For the App Router, follow the Next.js guide.
npm install @rowix/gifsnap-react2. Store the selected GIF
onSelect receives a GifSnapGif object. Keep that object in your state so your composer can use its media URL, dimensions, title, and source metadata together.
import { useState } from 'react';
import { GifPicker, type GifSnapGif } from '@rowix/gifsnap-react';
import '@rowix/gifsnap-react/styles.css';
export default function MessageComposer() {
const [gif, setGif] = useState<GifSnapGif | null>(null);
return (
<>
<GifPicker onSelect={setGif} theme="system" />
{gif && (
<img src={gif.url} alt={gif.title || 'Selected GIF'}
width={gif.width} height={gif.height}
style={{ maxWidth: '100%', height: 'auto' }} />
)}
</>
);
}3. Fit it to your interface
The picker can follow the operating system or use an explicit appearance. If your app has its own theme setting, pass that value as theme so both interfaces stay in sync.
<GifPicker
onSelect={setSelectedGif}
theme="dark"
initialQuery="celebrate"
pageSize={12}
className="composer-picker"
/>| Prop | Purpose |
|---|---|
onSelect | Required callback receiving the selected GifSnapGif. |
theme | light, dark, or system. |
initialQuery | Start with a search. An empty query browses trending GIFs. |
pageSize | Requested number of items in each batch. |
className | Add a class for your container styling. |
client | Use a client returned by createGifSnapClient with your configuration. |
Use the media in your app
The picker handles selection; your app decides how to attach, send, or save it. Use url unchanged to display and send the selected animation, as in the example above. The preview_url field is a poster or legacy preview and may be a still image. URLs may point to external storage, and the returned format may be WebP or another supported image format.
For a custom results grid, the optional animated_preview provides a smaller animation when one is available. Match its MIME type to your renderer: GIF and WebP work in an image element; MP4 and WebM need a video element. Fall back to url when that rendition is absent, unsupported, or fails to load. See the media response reference for validation and fallback details.
Reserve media space with width and height, provide fallback alt text for an empty title, and handle an image that becomes unavailable. Keep source metadata when storing a selection.
Need custom search controls? Use the JavaScript client and build your own interface.
Let’s get GIFs working in your app.
Choosing an SDK, moving an existing picker, or stuck on your first request? Tell us about your app and stack so we can help with your integration.
Ask a question or discuss a $299 implementation pilot. No payment is taken on this website.