Skip to content

Commit f9c6e7b

Browse files
use action and reducer
1 parent b87555b commit f9c6e7b

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

redux/npxapp/src/App.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ import './App.css'
44
function App() {
55
return (
66
<>
7-
<h1>welcome to redux</h1>
7+
<div className='container'>
8+
9+
<h1>Increment/Decrement counter</h1>
10+
<h4>using React and redux</h4>
11+
12+
<div className='quantity'>
13+
<a className='quantity_minus' title='Decrement'><span>-</span></a>
14+
<input name='quantity' type='text' className='quantity_input' value= "0" />
15+
<a className='quantity_plus' title='Increment'><span>+</span></a>
16+
</div>
17+
</div>
818
</>
919
)
1020
}

redux/npxapp/src/actions/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
export const incNumber = () =>{
3+
return{
4+
type: "INCREMENT"
5+
}
6+
}
7+
8+
export const decNumber = () =>{
9+
return{
10+
type: "DECREMENT"
11+
}
12+
}

redux/npxapp/src/reducers/index.js

Whitespace-only changes.

redux/npxapp/src/reducers/updown.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
3+
const initialState = 0;
4+
5+
const changeTheNumber = (state = initialState , action) =>{
6+
switch(action.type){
7+
case "INCREMENT": return state + 1;
8+
case "DECREMENT": return state - 1;
9+
default: return state;
10+
}
11+
}

redux/npxapp/src/store.js

Whitespace-only changes.

0 commit comments

Comments
 (0)