-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Digvijay Upadhyay
committed
Aug 29, 2018
1 parent
9853cd9
commit eed332c
Showing
7 changed files
with
103 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const textChange = text => ({ | ||
type: 'TEXT_CHANGE', | ||
text | ||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,4 @@ | ||
body { | ||
font-size: 13px; | ||
|
||
div { | ||
margin: auto; | ||
padding: 20px; | ||
} | ||
padding: 2rem; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { textChange } from '../Actions'; | ||
|
||
class Home extends Component { | ||
render() { | ||
let input | ||
return ( | ||
<h2> | ||
Home Page | ||
</h2> | ||
<div> | ||
<h2> | ||
Home Page | ||
</h2> | ||
<div>Write a name and check it in SomePage Link</div> | ||
<input | ||
type="text" | ||
onChange={e => | ||
{ | ||
this.props.updateText(input.value) | ||
} | ||
} | ||
ref={node => { | ||
input = node | ||
}} | ||
/> | ||
<div> | ||
You typed: {this.props.text} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Home; | ||
const mapStateToText = state => ({ | ||
text: state.appReducer.text, | ||
}); | ||
|
||
const mapDispatch = dispatch => ({ | ||
updateText: text => dispatch(textChange(text)) | ||
}); | ||
|
||
|
||
export default connect(mapStateToText, mapDispatch)(Home); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { combineReducers } from 'redux'; | ||
|
||
// you can keep this reducer in another file and import it from there | ||
// I have kept it here for simplifying | ||
// I would recommend you to break the reducers and actions as well | ||
const appReducer = (state = {}, action) => { | ||
switch (action.type) { | ||
case 'TEXT_CHANGE': | ||
return { | ||
text: action.text | ||
} | ||
default: | ||
return state | ||
} | ||
} | ||
|
||
export default combineReducers({ | ||
appReducer | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
import React from 'react'; | ||
import './App.scss' | ||
import ReactDOM from 'react-dom'; | ||
import { Provider } from 'react-redux' | ||
import { createStore } from 'redux' | ||
import rootReducer from './Reducers' | ||
import App from './App'; | ||
import { HashRouter } from 'react-router-dom' | ||
|
||
const store = createStore(rootReducer) | ||
|
||
const render = () => | ||
ReactDOM.render( | ||
<HashRouter> | ||
<App/> | ||
</HashRouter>, | ||
<Provider store={store}> | ||
<HashRouter> | ||
<App/> | ||
</HashRouter> | ||
</Provider>, | ||
document.getElementById('index')); | ||
|
||
render(); |