You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from "react";
  2. import { StyleSheet, Text, TouchableOpacity, View } from "react-native";
  3. import { useDispatch, useSelector } from "react-redux";
  4. import { decrement, increment } from "../store/actions";
  5. export const Counter = () => {
  6. const dispatch = useDispatch()
  7. const value = useSelector(s => s.test.value)
  8. return (
  9. <View style={[{ width: '75%' }]}>
  10. <Text style={[styles.textAlignCenter]}>{value}</Text>
  11. <View style={[styles.row, styles.justifySpaceBetween]}>
  12. <TouchableOpacity style={[styles.button, styles.justifyCenter]} onPress={() => dispatch(increment())}>
  13. <Text style={[styles.textAlignCenter]}>Increment</Text>
  14. </TouchableOpacity>
  15. <TouchableOpacity style={[styles.button, styles.justifyCenter]} onPress={() => dispatch(decrement())}>
  16. <Text style={[styles.textAlignCenter]}>Decrement</Text>
  17. </TouchableOpacity>
  18. </View>
  19. </View>
  20. )
  21. }
  22. const styles = StyleSheet.create({
  23. row: {
  24. flexDirection: "row",
  25. },
  26. flex: {
  27. flex: 1
  28. },
  29. justifySpaceBetween: {
  30. justifyContent: 'space-between'
  31. },
  32. button: {
  33. backgroundColor: "#D9F1EC",
  34. padding: '3%',
  35. marginTop: '10%'
  36. },
  37. textAlignCenter: {
  38. textAlign: 'center'
  39. },
  40. justifyCenter: {
  41. justifyContent: 'center'
  42. },
  43. alignCenter: {
  44. alignItems: 'center'
  45. }
  46. })