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

react-native-theme-provider-next

v0.5.0

Published

provide custom theme config for react native

Readme

react-native-theme-provider-next

npm version license

A flexible and type-safe theme provider for React Native applications. Create custom theme configurations with full TypeScript support, context-based theming, and easy theme overrides.

✨ Features

  • 🎨 Custom Theme Support - Define your own theme structure with full TypeScript generics
  • 🔄 Theme Context - Access theme anywhere in your component tree via React Context
  • 🪝 useTheme Hook - Use themes with optional partial overrides
  • 🎁 withTheme HOC - Wrap class components to inject theme props
  • 🔀 Deep Merge - Seamlessly merge theme overrides with base theme using deepmerge
  • 📦 Lightweight - Minimal dependencies, maximum flexibility

📦 Installation

# Using npm
npm install react-native-theme-provider-next

# Using yarn
yarn add react-native-theme-provider-next

🚀 Quick Start

1. Define Your Theme

// theme.ts
const LightTheme = {
  dark: false,
  colors: {
    primary: '#6200ee',
    background: '#ffffff',
    text: '#000000',
    border: '#e0e0e0',
  },
  spacing: {
    small: 8,
    medium: 16,
    large: 24,
  },
};

const DarkTheme = {
  dark: true,
  colors: {
    primary: '#bb86fc',
    background: '#121212',
    text: '#ffffff',
    border: '#333333',
  },
  spacing: {
    small: 8,
    medium: 16,
    large: 24,
  },
};

export type AppTheme = typeof LightTheme;
export { LightTheme, DarkTheme };

2. Create Theming

// theming.ts
import { createTheming } from 'react-native-theme-provider-next';
import { LightTheme, type AppTheme } from './theme';

export const { ThemeContext, ThemeProvider, useTheme, withTheme } =
  createTheming<AppTheme>(LightTheme);

3. Wrap Your App

// App.tsx
import React, { useState } from 'react';
import { ThemeProvider } from './theming';
import { LightTheme, DarkTheme } from './theme';
import MainScreen from './MainScreen';

export default function App() {
  const [isDark, setIsDark] = useState(false);

  return (
    <ThemeProvider theme={isDark ? DarkTheme : LightTheme}>
      <MainScreen onToggleTheme={() => setIsDark(!isDark)} />
    </ThemeProvider>
  );
}

4. Use Theme in Components

Using the useTheme Hook

import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { useTheme } from './theming';

function MyComponent() {
  const theme = useTheme();

  return (
    <View
      style={[styles.container, { backgroundColor: theme.colors.background }]}
    >
      <Text style={{ color: theme.colors.text }}>Hello, Themed World!</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 16,
  },
});

Using useTheme with Overrides

You can pass partial theme overrides directly to useTheme:

function CustomButton() {
  // Override only specific values
  const theme = useTheme({
    colors: {
      primary: '#ff5722', // Override primary color for this component
    },
  });

  return (
    <TouchableOpacity style={{ backgroundColor: theme.colors.primary }}>
      <Text>Custom Styled Button</Text>
    </TouchableOpacity>
  );
}

Using the withTheme HOC

For class components or when you prefer HOCs:

import React from 'react';
import { View, Text } from 'react-native';
import { withTheme } from './theming';
import type { AppTheme } from './theme';

interface Props {
  theme: AppTheme;
  title: string;
}

class ThemedCard extends React.Component<Props> {
  render() {
    const { theme, title } = this.props;

    return (
      <View
        style={{
          backgroundColor: theme.colors.background,
          padding: theme.spacing.medium,
        }}
      >
        <Text style={{ color: theme.colors.text }}>{title}</Text>
      </View>
    );
  }
}

export default withTheme(ThemedCard);

📖 API Reference

createTheming<T>(defaultTheme: T)

Creates a complete theming system based on your default theme.

Parameters:

  • defaultTheme: T - Your default theme object

Returns: ThemingType<T>

  • ThemeContext - React Context holding the current theme
  • ThemeProvider - Provider component to wrap your app
  • useTheme(overrides?) - Hook to access and optionally override theme
  • withTheme(Component) - HOC to inject theme into class components

ThemeProvider

<ThemeProvider theme={myTheme}>{children}</ThemeProvider>

Props:

  • theme?: T - Theme object (defaults to the theme passed to createTheming)
  • children: ReactNode - Child components

useTheme(overrides?)

const theme = useTheme();
// or with overrides
const theme = useTheme({ colors: { primary: '#custom' } });

Parameters:

  • overrides?: DeepPartial<T> - Optional partial theme to merge with current theme

Returns: T - The merged theme object

withTheme(Component)

const ThemedComponent = withTheme(MyComponent);

Parameters:

  • Component: React.ComponentType<P> - Component that expects a theme prop

Returns: A new component with theme prop injected

deepmerge

Re-exported from the deepmerge package for convenience:

import { deepmerge } from 'react-native-theme-provider-next';

const mergedTheme = deepmerge(baseTheme, overrideTheme);

🔧 TypeScript Support

This library is built with TypeScript and provides full type safety. Your theme type will be inferred throughout your application:

// Define your theme type
type MyTheme = {
  colors: {
    primary: string;
    secondary: string;
  };
  fonts: {
    regular: string;
    bold: string;
  };
};

// Create theming with your type
const { useTheme, ThemeProvider } = createTheming<MyTheme>(defaultTheme);

// useTheme() will return MyTheme
// Overrides will be type-checked as DeepPartial<MyTheme>

🤝 Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

📄 License

MIT © lucy.li


Made with ❤️ using create-react-native-library