Last active
July 18, 2023 12:48
-
-
Save dineshdeveloper1/6f09212571617503dbdc40046b019429 to your computer and use it in GitHub Desktop.
React Redux Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const incrementNumber = () => { | |
return{ | |
type: 'INCREMENT' | |
} | |
} | |
export const decrementNumber = () => { | |
return{ | |
type: 'DECREMENT' | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import './App.css'; | |
import { useSelector, useDispatch } from 'react-redux'; | |
import { incrementNumber, decrementNumber } from './action/index' | |
function App() { | |
const myState = useSelector((state) => state.changeTheNumber) | |
const dispatch = useDispatch() | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<h2>Calculation in React Redux</h2> | |
<div className='calculation_block'> | |
<button onClick={() => dispatch(decrementNumber())}>-</button> | |
<input type='text' value={myState} /> | |
<button onClick={() => dispatch(incrementNumber())}>+</button> | |
</div> | |
</header> | |
</div> | |
); | |
} | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createStore } from 'redux' | |
import rootReducer from "./reducer/index"; | |
const store = createStore(rootReducer, window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()) | |
export default store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import appStore from './dataStore'; | |
import { Provider } from 'react-redux'; | |
const root = ReactDOM.createRoot(document.getElementById('root')); | |
root.render( | |
<React.StrictMode> | |
<Provider store={appStore}> | |
<App /> | |
</Provider> | |
</React.StrictMode> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install redux | |
npm install react-redux | |
for more detail - https://redux.js.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const intitalState = 0; | |
const changeTheNumber = (state=intitalState, action) => { | |
switch(action.type){ | |
case 'INCREMENT' : return state + 1 | |
case 'DECREMENT' : return state - 1 | |
default : return state; | |
} | |
} | |
export default changeTheNumber |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import changeTheNumber from "./calculation"; | |
import { combineReducers } from 'redux' | |
const rootReducer = combineReducers({ | |
changeTheNumber | |
}) | |
export default rootReducer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment