Redux
Redux
Components:
__________
1. AcOntainer.js
function AcContainer(props) {
return (
<div>
<h2>No of ACS : {props.noOfACS}</h2>
<button onClick={props.buyAC}>Buy AC</button>
</div>
)
}
2. TVcontainer.js
_________________
function TvContainer(props) {
return (
<div>TvContainer
<h2>No of TVS : {props.noOfTVS}</h2>
<button onClick={props.buyTV}>Buy TV</button>
</div>
)
}
Redux
________
AC:
1. ACaction.js
import { BUY_AC } from "./Actypes"
2. Acreducer.js
import { BUY_AC } from "./Actypes"
const initialState = {
noOfACS : 20
}
const acreducer = (state = initialState, action) => {
switch(action.type) {
case BUY_AC : return {
...state,
noOfACS : state.noOfACS-1
}
default : return state
}
}
TV:
1. TVaction.js
const initialState = {
noOfTVS : 10
}
const tvreducer = (state = initialState, action) => {
switch(action.type) {
case BUY_TV : return {
...state,
noOfTVS : state.noOfTVS-1
}
default : return state
3. TVTypes.js
export const BUY_TV = 'BUY_TV'