This React Native app shows a number and two buttons to add or subtract from it. Zustand keeps the number state simple and shared inside the app.
import React from 'react'
import { View, Text, Button } from 'react-native'
import create from 'zustand'
const useStore = create(set => ({
count: 0,
increase: () => set(state => ({ count: state.count + 1 })),
decrease: () => set(state => ({ count: state.count - 1 }))
}))
export default function Counter() {
const { count, increase, decrease } = useStore()
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text style={{ fontSize: 48, marginBottom: 20 }} accessibilityLabel="Current count">{count}</Text>
<View style={{ flexDirection: 'row', gap: 20 }}>
<Button title="-" onPress={decrease} accessibilityLabel="Decrease count" />
<Button title="+" onPress={increase} accessibilityLabel="Increase count" />
</View>
</View>
)
}