mirror of
https://github.com/seigler/triplebyte-react-spa
synced 2025-07-26 23:26:10 +00:00
Initial commit from Create Next App
This commit is contained in:
commit
5684ef36ec
10 changed files with 7925 additions and 0 deletions
36
components/counter.js
Normal file
36
components/counter.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
import React from 'react'
|
||||
import { useSelector, useDispatch } from 'react-redux'
|
||||
|
||||
const useCounter = () => {
|
||||
const count = useSelector(state => state.count)
|
||||
const dispatch = useDispatch()
|
||||
const increment = () =>
|
||||
dispatch({
|
||||
type: 'INCREMENT',
|
||||
})
|
||||
const decrement = () =>
|
||||
dispatch({
|
||||
type: 'DECREMENT',
|
||||
})
|
||||
const reset = () =>
|
||||
dispatch({
|
||||
type: 'RESET',
|
||||
})
|
||||
return { count, increment, decrement, reset }
|
||||
}
|
||||
|
||||
const Counter = () => {
|
||||
const { count, increment, decrement, reset } = useCounter()
|
||||
return (
|
||||
<div>
|
||||
<h1>
|
||||
Count: <span>{count}</span>
|
||||
</h1>
|
||||
<button onClick={increment}>+1</button>
|
||||
<button onClick={decrement}>-1</button>
|
||||
<button onClick={reset}>Reset</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Counter
|
Loading…
Add table
Add a link
Reference in a new issue