~firefoxreact-appvite-appsrccomponents
3 itemsDownload ./*

..
Counter.tsx
MousePosition.tsx
WindowSize.tsx


componentsCounter.tsx
1 KB• 2•  3 days ago•  DownloadRawClose
3 days ago•  2

{}
//import { useState } from 'react'
import React from 'react'
//import { useSelector, useDispatch } from 'react-redux';
//import { RootState, AppDispatch } from './redux/store'; // replaced with hooks
import { useAppSelector, useAppDispatch } from '../redux/hooks';
import { increment, decrement, incrementByAmount } from '../redux/counter/counterSlice';

const Counter: React.FC = () => {
  //const [count, setCount] = useState(0)

  // Access the counter value from the store
  //const count = useSelector((state: RootState) => state.counter.value);
  // Get the dispatch function
  //const dispatch = useDispatch<AppDispatch>();
  
  const count = useAppSelector((state) => state.counter.value);
  const dispatch = useAppDispatch();

  return (
    <>
      {/*<button onClick={() => setCount((count) => count + 1)}>
        Hearts ❤️ {count}
      </button>*/}
      <h3>Hearts: ❤️ {count}</h3>
      <br />
      <button className="bg-indigo-600 hover:bg-purple-500 text-white font-bold py-2 px-4 rounded-full" onClick={() => dispatch(increment())}>Increment</button>
      <button className="bg-indigo-600 hover:bg-purple-500 text-white font-bold py-2 px-4 rounded-full" onClick={() => dispatch(decrement())}>Decrement</button>
      <br />
      <br />
      <button className="bg-indigo-600 hover:bg-purple-500 text-white font-bold py-2 px-4 rounded-full" onClick={() => dispatch(incrementByAmount(5))}>Increment by 5</button>
    </>
  )
}

export default Counter;

Top
©twily.info 2013 - 2025
twily at twily dot info



2 274 586 visits
... ^ v