Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
Coding works best on desktop or with an external keyboard.
Multiple independent counters in a single view using NativeBase.
import React, { useState } from 'react';
import { NativeBaseProvider, Box, Button, VStack, Text } from 'native-base';
export default function App() {
const [counters, setCounters] = useState([0,0,0]);
const increment = i => setCounters(counters.map((c,index) => index===i ? c+1 : c));
const decrement = i => setCounters(counters.map((c,index) => index===i ? c-1 : c));
return (
<NativeBaseProvider>
<Box safeArea p={4}>
<VStack space={4} alignItems="center">
{counters.map((c,i) => (
<Box key={i} alignItems="center">
<Text fontSize="xl">Counter {i+1}: {c}</Text>
<Button onPress={() => increment(i)} style={{ marginRight:5 }}>+</Button>
<Button onPress={() => decrement(i)}>-</Button>
</Box>
))}
</VStack>
</Box>
</NativeBaseProvider>
);
}NativeBase is an open-source UI component library for React Native, providing a set of cross-platform, customizable components that accelerate mobile app development with consistent design.
Origin & Creator
Developed by GeekyAnts, first released in 2016 to simplify React Native UI development and provide a consistent cross-platform component library.
Industrial Note
NativeBase is widely used for startups, enterprise mobile apps, and cross-platform React Native projects that need rapid prototyping and production-ready UI components.