Last active
July 7, 2018 12:49
-
-
Save saigowthamr/b923a643d6e9e674f810871a69c8a6e5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 React from 'react'; | |
import { getState, dispatch} from './store' | |
class Todo extends React.Component { | |
OnAddHandler = () => { | |
if (this.input.value) | |
dispatch({ | |
type: 'ADD_TODO', | |
text: this.input.value | |
}) | |
this.input.value = '' | |
} | |
render() { | |
return ( | |
<div> | |
<input placeholder="Some Text" ref={node => { | |
this.input = node | |
}} | |
/> | |
<button onClick={this.OnAddHandler} >Add Todo</button> | |
<ul> | |
{getState().todos.map((tod) => | |
<li key={Math.random()}>{tod}</li> | |
)} | |
</ul> | |
</div> | |
) | |
} | |
} | |
export default Todo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment