React Native Simple Todo App - React-native Typing CST Test
Loading…
React Native Simple Todo App — React-native Code
Demonstrates a simple React Native app with a list of todos, adding and removing tasks, and state management using useState.
import React, { useState } from 'react';
import { View, Text, TextInput, Button, FlatList } from 'react-native';
export default function App() {
const [todos, setTodos] = useState([]);
const [text, setText] = useState('');
const addTodo = () => {
setTodos([...todos, { key: String(todos.length), title: text }]);
setText('');
};
return (
<View style={{ padding: 20 }}>
<TextInput value={text} onChangeText={setText} placeholder='New Todo' />
<Button title='Add' onPress={addTodo} />
<FlatList data={todos} renderItem={({ item }) => <Text>{item.title}</Text>} />
</View>
);
}React-native Language Guide
React Native is a popular open-source framework for building cross-platform mobile applications using JavaScript and React, allowing developers to write a single codebase for iOS and Android while delivering near-native performance.
Primary Use Cases
- ▸Cross-platform mobile applications for iOS and Android
- ▸Consumer-facing apps with rich UI and interactions
- ▸Enterprise mobile solutions and dashboards
- ▸Prototyping and MVP development
- ▸Apps requiring some native module integration
Notable Features
- ▸Write once, run on both iOS and Android
- ▸Declarative UI with React components
- ▸Hot reload and fast refresh for quick iteration
- ▸Access to native modules and APIs
- ▸Large ecosystem of libraries and community support
Origin & Creator
Created by Facebook in 2015 and maintained by Meta and the React Native community.
Industrial Note
React Native is widely used for cross-platform mobile apps in startups and enterprises, enabling rapid development with a single codebase while achieving near-native performance.
Quick Explain
- ▸React Native enables development of mobile apps using React components and JavaScript/TypeScript.
- ▸It uses a bridge to communicate between JavaScript and native modules for high-performance rendering.
- ▸Supports hot reloading and fast refresh for rapid development.
- ▸Has a large ecosystem of third-party libraries and UI components.
- ▸Allows integrating native code when needed for platform-specific features.
Core Features
- ▸React-based component model
- ▸JS-to-native bridge
- ▸Built-in navigation via React Navigation
- ▸State management via Redux, MobX, or Context API
- ▸Styling with Flexbox and StyleSheet API
Learning Path
- ▸Week 1: Learn React fundamentals
- ▸Week 2: Setup React Native environment and build simple components
- ▸Week 3: Navigation and state management
- ▸Week 4: Networking and APIs integration
- ▸Week 5: Native modules, performance optimization, deployment
Practical Examples
- ▸Build a to-do list app
- ▸Create a chat app with real-time updates
- ▸Integrate REST or GraphQL API
- ▸Use Redux for state management across screens
- ▸Implement push notifications and camera access
Comparisons
- ▸React Native vs Flutter - RN uses JS, easier for web devs; Flutter uses Dart and has custom rendering engine
- ▸React Native vs Xamarin - RN is JS-based; Xamarin uses C# and .NET
- ▸React Native vs Native iOS/Android - RN cross-platform, may need native bridges; native gives full performance and API access
- ▸React Native vs Ionic - RN near-native performance; Ionic web-based hybrid apps
- ▸React Native vs Kotlin Multiplatform - RN JS-based, faster iteration; Kotlin MP allows sharing business logic but UIs are platform-specific
Strengths
- ▸Cross-platform development with one codebase
- ▸Near-native performance for most apps
- ▸Large community and ecosystem
- ▸Integration with existing native code
- ▸Rapid development and iteration
Limitations
- ▸Complex native modules require Objective-C/Swift or Java/Kotlin knowledge
- ▸Performance-sensitive apps may need full native code
- ▸Debugging bridge-related issues can be tricky
- ▸Smaller set of native UI components than pure native frameworks
- ▸Upgrade process can be challenging between versions
When NOT to Use
- ▸Performance-critical 3D or game apps
- ▸Apps needing deep platform-specific native integration
- ▸Projects requiring minimal bundle size
- ▸Apps with very complex animations needing native frameworks
- ▸Teams without JS/React experience
Cheat Sheet
- ▸npx react-native init MyApp - create project
- ▸npx react-native run-ios - run on iOS simulator
- ▸npx react-native run-android - run on Android emulator
- ▸StyleSheet.create({}) - define styles
- ▸useState/useEffect - manage component state and lifecycle
FAQ
- ▸Is React Native open-source? -> Yes, MIT license.
- ▸Does React Native support TypeScript? -> Yes, fully supported.
- ▸Can React Native apps access device APIs? -> Yes, via native modules.
- ▸Is React Native suitable for enterprise apps? -> Yes, widely used in production.
- ▸How do you debug React Native apps? -> Using React DevTools, console, and Flipper.
30-Day Skill Plan
- ▸Master React component lifecycle and hooks
- ▸Understand platform-specific APIs
- ▸Write optimized and reusable components
- ▸Integrate third-party libraries efficiently
- ▸Deploy and maintain cross-platform apps
Final Summary
- ▸React Native is a cross-platform mobile framework using JS and React.
- ▸Allows building iOS and Android apps with a single codebase.
- ▸Near-native performance for most applications.
- ▸Extensive ecosystem and community support.
- ▸Supports native module integration for platform-specific needs.
Project Structure
- ▸App.js - main entry point
- ▸components/ - reusable components
- ▸screens/ - screen-level components
- ▸assets/ - images, fonts, icons
- ▸package.json - project dependencies
Monetization
- ▸Open-source (MIT license)
- ▸Commercial apps across iOS/Android
- ▸Subscription or in-app purchase apps
- ▸Enterprise mobile solutions
- ▸Integration with ad and analytics platforms
Productivity Tips
- ▸Use reusable components and hooks
- ▸Optimize FlatList for large datasets
- ▸Use fast refresh for iterative development
- ▸Leverage TypeScript for type safety
- ▸Profile and optimize performance early
Basic Concepts
- ▸Component - reusable UI element
- ▸Props - inputs to components
- ▸State - internal data for components
- ▸StyleSheet - styling API for components
- ▸Navigation - moving between screens using React Navigation
Official Docs
- ▸https://reactnative.dev/docs/getting-started
- ▸React Native GitHub repository
- ▸Community tutorials and guides