Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update App.js #260

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions react-redux-master/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
125 changes: 79 additions & 46 deletions react-redux-master/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions react-redux-master/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^13.0.0",
"@testing-library/user-event": "^13.2.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.0.4",
"react-scripts": "5.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-redux": "^8.1.3",
"react-scripts": "^5.0.1",
"react-service-worker": "^0.1.1",
"redux": "^4.2.0",
"web-vitals": "^2.1.0"
"redux": "^4.2.1",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
Expand Down
9 changes: 8 additions & 1 deletion react-redux-master/src/actions/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
//actions
const increment = (val) => {
return {
type : 'INCREMENT',
inc : val
}
}

export default increment;
12 changes: 12 additions & 0 deletions react-redux-master/src/components/DivPanel.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import React from 'react'
import { useSelector } from 'react-redux';

const DivPanel = () =>{
let counterVal = useSelector(state => state.counter)
return (
<div>
The present value of counter is {counterVal}
</div>
);
}

export default DivPanel;
12 changes: 12 additions & 0 deletions react-redux-master/src/components/MainPanel.js
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import React from 'react'
import MyButton from './MyButton'
import DivPanel from './DivPanel';

const MainPanel = ()=>{
return (
<div>
This is main panel <MyButton></MyButton>
<DivPanel></DivPanel>
</div>
);
}
export default MainPanel;
11 changes: 11 additions & 0 deletions react-redux-master/src/components/MyButton.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import React from 'react'
import { useDispatch} from 'react-redux';
import increment from '../actions'

const MyButton = ()=>{
let dispatch = useDispatch();
return (
<button onClick={()=>dispatch(increment(1))}>Increase counter</button>
);
}

export default MyButton;
11 changes: 4 additions & 7 deletions react-redux-master/src/index.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
// import * as serviceWorker from './serviceWorker';

import {createStore} from 'redux';
import {Provider} from 'react-redux'
import { Provider } from 'react-redux'
import myReducers from './reducers'

import { legacy_createStore as createStore } from 'redux';;

//Create the store
const myStore = createStore(myReducers);

//This will console log the current state everytime the state changes
myStore.subscribe(()=>console.log(myStore.getState()));
myStore.subscribe(() => console.log(myStore.getState()));

//Enveloping the App inside the Provider, ensures that the states in the store are available
//throughout the application
ReactDOM.render(<Provider store={myStore}><App/></Provider>, document.getElementById('root'));
ReactDOM.render(<Provider store={myStore}><App /></Provider>, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
Expand Down
15 changes: 14 additions & 1 deletion react-redux-master/src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
//reducers
import {combineReducers} from 'redux'

const counter = (state=0,action)=>{
if(action.type === 'INCREMENT') {
//This will increase the value of counter by the value passed to the increment method
return state+action.inc;
}
//Returns the current value of the counter
return state;
}

const myReducers = combineReducers({counter});

export default myReducers;
Loading