Skip to content
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
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"dependencies": {
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-scripts": "2.1.3"
"react-redux": "8.0.2",
"react-script": "2.0.5",
"react-scripts": "2.1.3",
"redux": "4.2.0"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -25,4 +28,4 @@
"not ie <= 11",
"not op_mini all"
]
}
}
Binary file modified public/favicon.ico
100755 → 100644
Binary file not shown.
31 changes: 31 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from "react";
// import store from "./components/redux/flipAction";
import { connect } from "react-redux";

const mapStateToProps = (state) => {
console.log(state);
return {
currentState: state
};
};
const mapDispatchToProps = (dispatch) => {
return {
toggle: () => dispatch({ type: "TOGGLE" })
};
};
class App extends React.Component {
render() {
const lightedness = this.props.currentState ? "lit" : "dark";
return (
<div className={`room ${lightedness}`}>
the room is {lightedness}
<br />
<div>
<h1>{lightedness}</h1>
</div>
<button onClick={this.props.toggle}>flip</button>
</div>
);
}
}
export default connect(mapStateToProps, mapDispatchToProps)(App);
14 changes: 14 additions & 0 deletions src/components/redux/flipAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createStore } from "redux";
import { TOGGLE } from "./flipInfo";
let intialState = true;
const reducerFun = (currentState = intialState, action) => {
switch (action.type) {
case TOGGLE:
return !currentState;
default:
return currentState;
}
};

const store = createStore(reducerFun);
export default store;
1 change: 1 addition & 0 deletions src/components/redux/flipInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const TOGGLE = "TOGGLE";
23 changes: 6 additions & 17 deletions src/index.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";

import App from "./App";
import { Provider } from "react-redux";
import store from "./components/redux/flipAction";
class Room extends React.Component {
state = {
isLightOn: true
};

flipLight = () => {
this.setState({
isLightOn: !this.state.isLightOn
});
};

render() {
const lightedness = this.state.isLightOn ? "lit" : "dark";
return (
<div className={`room ${lightedness}`}>
the room is {lightedness}
<br />
<button onClick={this.flipLight}>flip</button>
</div>
<Provider store={store}>
<App />
</Provider>
);
}
}
Expand Down