Convert Figma logo to code with AI

react-native-community logoreact-native-template-typescript

👾 Clean and minimalist React Native template for a quick start with TypeScript.

1,861
397
1,861
10

Top Related Projects

A starter template for TypeScript and React Native with a detailed README describing how to use the two together.

17,313

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more!

32,626

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.

Material Design for React Native (Android & iOS)

A complete native navigation solution for React Native

Routing and navigation for your React Native apps

Quick Overview

React Native Template TypeScript is a template for creating React Native projects with TypeScript support. It provides a solid foundation for building mobile applications using React Native and TypeScript, offering a pre-configured development environment with essential tools and best practices.

Pros

  • Seamless integration of TypeScript with React Native
  • Pre-configured development environment with essential dependencies
  • Improved code quality and maintainability through static typing
  • Enhanced developer experience with better IDE support and autocompletion

Cons

  • Steeper learning curve for developers new to TypeScript
  • Slightly increased initial setup time compared to plain JavaScript projects
  • Potential compatibility issues with some third-party libraries not written in TypeScript

Code Examples

  1. Creating a functional component with TypeScript:
import React from 'react';
import { View, Text } from 'react-native';

interface GreetingProps {
  name: string;
}

const Greeting: React.FC<GreetingProps> = ({ name }) => {
  return (
    <View>
      <Text>Hello, {name}!</Text>
    </View>
  );
};

export default Greeting;
  1. Defining a custom hook with TypeScript:
import { useState, useEffect } from 'react';

const useCounter = (initialValue: number = 0) => {
  const [count, setCount] = useState(initialValue);

  const increment = () => setCount(prev => prev + 1);
  const decrement = () => setCount(prev => prev - 1);

  useEffect(() => {
    console.log(`Count changed to ${count}`);
  }, [count]);

  return { count, increment, decrement };
};

export default useCounter;
  1. Creating a styled component with TypeScript:
import styled from 'styled-components/native';

interface ButtonProps {
  primary?: boolean;
}

const Button = styled.TouchableOpacity<ButtonProps>`
  background-color: ${props => props.primary ? '#007AFF' : '#FFFFFF'};
  padding: 10px 20px;
  border-radius: 5px;
  border: 1px solid #007AFF;
`;

export default Button;

Getting Started

To create a new React Native project using this template, run the following command:

npx react-native init MyApp --template react-native-template-typescript

After the project is created, navigate to the project directory and start the development server:

cd MyApp
npx react-native start

To run the app on iOS or Android, use the following commands:

npx react-native run-ios
# or
npx react-native run-android

Competitor Comparisons

A starter template for TypeScript and React Native with a detailed README describing how to use the two together.

Pros of TypeScript-React-Native-Starter

  • More comprehensive setup with additional tools and configurations
  • Includes sample components and screens for a quick start
  • Provides a more opinionated structure for larger projects

Cons of TypeScript-React-Native-Starter

  • May be overwhelming for beginners or smaller projects
  • Less frequently updated compared to react-native-template-typescript
  • Potentially includes unnecessary dependencies for some use cases

Code Comparison

TypeScript-React-Native-Starter:

import React from 'react';
import { View, Text } from 'react-native';
import styles from './styles';

const HelloWorld: React.FC = () => (
  <View style={styles.container}>
    <Text style={styles.text}>Hello, World!</Text>
  </View>
);

react-native-template-typescript:

import React from 'react';
import { View, Text } from 'react-native';

const App = () => (
  <View>
    <Text>Hello, World!</Text>
  </View>
);

The TypeScript-React-Native-Starter example includes a separate styles file and uses a more structured component definition, while the react-native-template-typescript example is simpler and more straightforward. This reflects the overall difference in approach between the two templates, with TypeScript-React-Native-Starter providing a more comprehensive setup and react-native-template-typescript offering a minimal, flexible starting point.

17,313

Infinite Red's battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more!

Pros of Ignite

  • Provides a more comprehensive boilerplate with additional features like state management and navigation
  • Includes a CLI tool for generating components, screens, and other project elements
  • Offers a curated set of libraries and best practices for React Native development

Cons of Ignite

  • Steeper learning curve due to additional complexity and opinionated structure
  • May include unnecessary dependencies for simpler projects
  • Less flexibility in terms of project structure and technology choices

Code Comparison

react-native-template-typescript:

import React from 'react';
import { View, Text } from 'react-native';

const App = () => (
  <View>
    <Text>Hello, World!</Text>
  </View>
);

Ignite:

import React from 'react'
import { observer } from 'mobx-react-lite'
import { ViewStyle } from 'react-native'
import { Screen, Text } from '../components'
import { useStores } from '../models'

export const WelcomeScreen = observer(function WelcomeScreen() {
  // ... more code here
})

The react-native-template-typescript provides a minimal TypeScript setup for React Native, while Ignite offers a more structured approach with additional features like state management (MobX) and custom components. Ignite's boilerplate is more opinionated and includes more dependencies out of the box, which can be beneficial for larger projects but may be overkill for simpler applications.

32,626

An open-source framework for making universal native apps with React. Expo runs on Android, iOS, and the web.

Pros of Expo

  • Simplified development process with a comprehensive set of tools and services
  • Easier to get started, especially for beginners
  • Access to a wide range of pre-built components and APIs

Cons of Expo

  • Limited access to native modules and custom native code
  • Larger app size due to included libraries and dependencies
  • Potential performance limitations for complex applications

Code Comparison

Expo:

import React from 'react';
import { Text, View } from 'react-native';
import { Camera } from 'expo-camera';

export default function App() {
  return (
    <View>
      <Camera style={{ flex: 1 }} />
      <Text>Hello, Expo!</Text>
    </View>
  );
}

react-native-template-typescript:

import React from 'react';
import { Text, View } from 'react-native';
import { RNCamera } from 'react-native-camera';

const App: React.FC = () => {
  return (
    <View>
      <RNCamera style={{ flex: 1 }} />
      <Text>Hello, React Native!</Text>
    </View>
  );
};

export default App;

The main differences in the code examples are:

  • Expo uses expo-camera, while react-native-template-typescript uses react-native-camera
  • react-native-template-typescript includes TypeScript type annotations
  • Expo's setup is slightly simpler, with fewer imports and no explicit type definitions

Material Design for React Native (Android & iOS)

Pros of React Native Paper

  • Comprehensive UI component library with Material Design
  • Customizable themes and styles for consistent app appearance
  • Active development and community support

Cons of React Native Paper

  • Larger bundle size due to additional components
  • Learning curve for using Paper-specific components
  • May require additional setup and configuration

Code Comparison

React Native Paper:

import { Button } from 'react-native-paper';

const MyComponent = () => (
  <Button mode="contained" onPress={() => console.log('Pressed')}>
    Press me
  </Button>
);

React Native Template TypeScript:

import { Button } from 'react-native';

const MyComponent = () => (
  <Button
    title="Press me"
    onPress={() => console.log('Pressed')}
  />
);

React Native Paper provides a more customizable and feature-rich Button component with built-in Material Design styling, while React Native Template TypeScript uses the default React Native Button component.

React Native Template TypeScript offers a minimal setup with TypeScript support, making it ideal for developers who want a clean slate to build upon. It's lighter and requires less initial configuration.

React Native Paper is better suited for projects that require a comprehensive UI library with pre-built components and consistent styling across the application. It's particularly useful for developers aiming to implement Material Design in their React Native apps.

A complete native navigation solution for React Native

Pros of react-native-navigation

  • Native navigation performance and feel
  • Extensive customization options for navigation elements
  • Support for complex navigation patterns like deep linking and tab-based navigation

Cons of react-native-navigation

  • Steeper learning curve compared to simpler navigation solutions
  • Requires additional setup and configuration
  • May introduce compatibility issues with certain React Native versions or other libraries

Code Comparison

react-native-template-typescript (using React Navigation):

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

react-native-navigation:

import { Navigation } from 'react-native-navigation';

Navigation.registerComponent('Home', () => HomeScreen);
Navigation.registerComponent('Details', () => DetailsScreen);

Navigation.setRoot({
  root: {
    stack: {
      children: [
        { component: { name: 'Home' } },
      ],
    },
  },
});

The react-native-template-typescript uses React Navigation, which is more declarative and follows a component-based approach. react-native-navigation uses a more imperative API, requiring explicit registration of components and setting the root structure.

Routing and navigation for your React Native apps

Pros of react-navigation

  • Comprehensive navigation solution for React Native apps
  • Extensive documentation and community support
  • Flexible and customizable with various navigation patterns

Cons of react-navigation

  • Steeper learning curve for complex navigation scenarios
  • Requires additional setup and configuration
  • May introduce unnecessary complexity for simple apps

Code Comparison

react-navigation:

import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';

const Stack = createStackNavigator();

function App() {
  return (
    <NavigationContainer>
      <Stack.Navigator>
        <Stack.Screen name="Home" component={HomeScreen} />
        <Stack.Screen name="Details" component={DetailsScreen} />
      </Stack.Navigator>
    </NavigationContainer>
  );
}

react-native-template-typescript:

import React from 'react';
import { View, Text } from 'react-native';

const App: React.FC = () => {
  return (
    <View>
      <Text>Hello, TypeScript!</Text>
    </View>
  );
};

export default App;

The react-navigation repository focuses on providing a robust navigation solution for React Native apps, while react-native-template-typescript is a template for creating React Native projects with TypeScript support. The former offers more advanced features for app navigation, while the latter provides a starting point for TypeScript-based React Native development.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

This template is deprecated

React Native added first-class support for Typescript in version 0.71, with the base template now utilizing it. Additionally, the types have been integrated into the React Native repository. Although this template can still be used to generate projects with older versions of React Native, we will no longer update it. We would like to express our gratitude to all contributors for their efforts in enhancing this template over the years.

:space_invader: React Native Template TypeScript

Build Status Documentation Maintenance License: MIT

Clean and minimalist React Native template for a quick start with TypeScript.

:star: Features

  • Elegant usage directly within the React Native CLI
  • Consistent with the default React Native template
  • Minimal additional dependencies

:arrow_forward: Usage

npx react-native init MyApp --template react-native-template-typescript@6.12.10

See the below table to find out which version of the template to use.

React Native <=> Template Version

React NativeTemplate
0.706.12.*
0.696.11.*
0.686.10.*
0.676.9.*
0.666.8.*
0.656.7.*
0.646.6.*
0.636.5.*
0.626.4.*
0.616.3.*
0.606.2.*

:warning: React Native CLI

This template only works with the new CLI. Make sure you have uninstalled the legacy react-native-cli first (npm uninstall -g react-native-cli) for the below command to work. If you wish to not use npx, you can also install the new CLI globally (npm i -g @react-native-community/cli or yarn global add @react-native-community/cli).

If you tried the above and still get the react-native-template-react- native-template-typescript: Not found error, please try adding the --ignore-existing flag to force npx to ignore any locally installed versions of the CLI and use the latest.

Further information can be found here: https://github.com/react-native-community/cli#about

:computer: Contributing

Contributions are very welcome. Please check out the contributing document.

:bookmark: License

This project is MIT licensed.

NPM DownloadsLast 30 Days