Skip to content

Commit

Permalink
input加算機能実装
Browse files Browse the repository at this point in the history
  • Loading branch information
s-yoshiii committed May 10, 2022
1 parent eca8a5a commit 3c98465
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
13 changes: 0 additions & 13 deletions src/App.js

This file was deleted.

29 changes: 29 additions & 0 deletions src/App.jsx
@@ -0,0 +1,29 @@
import { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import "./App.css";
import { decrement, increment, incrementByAmount } from "./redux/counterSlice";

function App() {
const count = useSelector((state) => state.counter.value);
const dispatch = useDispatch();
const [incrementAmount, setIncrementAmount] = useState("2");
return (
<div className="App">
<h1>count:{count}</h1>
<input
type="number"
onChange={(e) => setIncrementAmount(e.target.value)}
value={incrementAmount}
/>
<button onClick={() => dispatch(increment())}>+</button>
<button onClick={() => dispatch(decrement())}>-</button>
<button
onClick={() => dispatch(incrementByAmount(Number(incrementAmount)))}
>
追加
</button>
</div>
);
}

export default App;
5 changes: 4 additions & 1 deletion src/redux/counterSlice.js
Expand Up @@ -12,7 +12,10 @@ export const counterSlice = createSlice({
decrement: (state) => {
state.value -= 1;
},
incrementByAmount: (state, action) => {
state.value += action.payload;
},
},
});
export const { increment, decrement } = counterSlice.actions;
export const { increment, decrement, incrementByAmount } = counterSlice.actions;
export default counterSlice.reducer;

0 comments on commit 3c98465

Please sign in to comment.