Skip to content

Instantly share code, notes, and snippets.

@saigowthamr
Last active July 7, 2018 12:49
Show Gist options
  • Save saigowthamr/b923a643d6e9e674f810871a69c8a6e5 to your computer and use it in GitHub Desktop.
Save saigowthamr/b923a643d6e9e674f810871a69c8a6e5 to your computer and use it in GitHub Desktop.
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