counter.tsx 1.2 KB

12345678910111213141516171819202122232425
  1. import React from "react";
  2. import { useSelector, useDispatch } from "react-redux";
  3. import { counterSlice, decrement, increment } from "../reducers/counterReducer";
  4. import { Button, Text, View } from "react-native";
  5. import store from "../store";
  6. export default function Counter() {
  7. /**********************************狀態管理**********************************/
  8. const value = useSelector((state: any) => state.counter.value);
  9. const dispatch = useDispatch();
  10. /**********************************狀態管理**********************************/
  11. /**********************************組件初始化**********************************/
  12. /**********************************組件初始化**********************************/
  13. /**********************************異步函數**********************************/
  14. /**********************************異步函數**********************************/
  15. return (
  16. <View>
  17. <View style={{ flexDirection: "row", alignItems: "center" }}>
  18. <Button title="Increment" onPress={() => dispatch(increment())} />
  19. <Text>{value}</Text>
  20. <Button title="Decrement" onPress={() => dispatch(decrement())} />
  21. </View>
  22. </View>
  23. );
  24. }