npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@media-sdk/native

v1.0.0

Published

React Native integration layer for @media-sdk/core

Downloads

286

Readme

@media-sdk/native

React Native integration layer for @media-sdk/core. Provides a context provider and hooks for photo/video search, pagination, and client access in React Native applications.

This package is Expo-agnostic — it uses React hooks only (no react-native imports). Works in bare React Native CLI apps and Expo apps alike.

Installation

pnpm add @media-sdk/core @media-sdk/native react

Peer Dependencies

  • React 18 or React 19

@media-sdk/core is installed automatically as a runtime dependency. No react-native peer dependency is required for the hooks package.

Provider

Create a PexelsMediaClient or PixabayMediaClient from core, then wrap your application with MediaProvider:

import { MediaProvider } from "@media-sdk/native";
import {
  ApiKeyProvider,
  PexelsMediaClient,
} from "@media-sdk/core";

const client = new PexelsMediaClient(
  new ApiKeyProvider(process.env.EXPO_PUBLIC_PEXELS_API_KEY!),
);

export function AppRoot({ children }: { children: React.ReactNode }) {
  return (
    <MediaProvider client={client}>
      {children}
    </MediaProvider>
  );
}

useMediaClient

Access the shared client from context. Must be called inside MediaProvider:

import { useMediaClient } from "@media-sdk/native";

function Example() {
  const client = useMediaClient();

  // client.searchPhotos(), client.getPhoto(), etc.
}

useMediaCapabilities

Read the active client's capabilities from context. Returns MediaCapabilities via getCapabilities(client):

import { useMediaCapabilities } from "@media-sdk/native";

function SearchTabs() {
  const caps = useMediaCapabilities();

  return (
    <>
      <Tab>Search</Tab>
      {caps.operations.curatedPhotos && <Tab>Curated</Tab>}
    </>
  );
}

Guard filter UI with caps.photoFilters / caps.videoFilters before passing values to search hooks.

useMediaSearch

Search photos with automatic fetching, pagination, and race protection:

import { useMediaSearch } from "@media-sdk/native";

function PhotoSearch({ query }: { query: string }) {
  const {
    data,
    loading,
    error,
    nextPage,
    previousPage,
    refetch,
  } = useMediaSearch({
    query,
    page: 1,
    perPage: 20,
    enabled: true,
  });

  if (loading) {
    return <Text>Loading...</Text>;
  }

  if (error) {
    return <Text>{error.message}</Text>;
  }

  return (
    <View>
      {data?.items.map((photo) => (
        <Text key={photo.id}>{photo.photographer}</Text>
      ))}
    </View>
  );
}

Options

{
  query: string;
  page?: number;      // initial page only (default: 1)
  perPage?: number;
  enabled?: boolean;  // default: true
  photoFilters?: PhotoSearchFilters;  // forwarded to searchPhotos unchanged
}

Result

{
  data: PaginatedResponse<Photo> | null;
  loading: boolean;
  error: Error | null;
  search: () => Promise<void>;
  nextPage: () => Promise<void>;
  previousPage: () => Promise<void>;
  refetch: () => Promise<void>;
}

useMediaVideos

Same contract as useMediaSearch, but for videos:

import { useMediaVideos } from "@media-sdk/native";

const {
  data,
  loading,
  error,
  nextPage,
  previousPage,
  refetch,
} = useMediaVideos({
  query: "nature",
  perPage: 20,
  videoFilters: {
    orientation: "landscape",
    size: "medium",
  },
});

Error Handling

Hooks surface errors from @media-sdk/core as native Error instances. Use isAbortError from core for custom searches:

import { isAbortError, MediaError } from "@media-sdk/core";

if (error instanceof MediaError) {
  if (error.code === "UNSUPPORTED_FILTER") {
    // handle unsupported filter
  }
}

if (isAbortError(error)) {
  // request was cancelled — hooks swallow aborts in UI state
}

Cancellation

Hooks abort in-flight requests when:

  • A new search starts (query, page, filters, or perPage changes)
  • refetch() is called while a request is active
  • The component unmounts

Aborted requests are silently ignored: error stays null and stale responses cannot overwrite newer state.

Architecture

React Native Application
       │
       ▼
@media-sdk/native   ← Provider + hooks (React only)
       │
       ▼
@media-sdk/core    ← API client, cache, types
       │
       ▼
Pexels / Pixabay API

Pair with @media-sdk/ui-native (when available) for presentational components, or build your own UI with RN primitives.

Public API

import {
  MediaProvider,
  useMediaCapabilities,
  useMediaClient,
  useMediaSearch,
  useMediaVideos,
  type UseMediaSearchOptions,
  type UseMediaSearchResult,
  type UseMediaVideosOptions,
  type UseMediaVideosResult,
} from "@media-sdk/native";

Versioning

This package is at 0.1.0 — pre-1.0 API may evolve. See the monorepo CHANGELOG for release notes.