summaryrefslogtreecommitdiff
path: root/sample-apps/react-todo
diff options
context:
space:
mode:
authorNick Van Doorn <vandoorn.nick@gmail.com>2019-03-04 03:03:39 -0800
committerNick Van Doorn <vandoorn.nick@gmail.com>2019-03-04 03:03:39 -0800
commit6dd6ad0ec6f483008792a2d08f317288e0634967 (patch)
tree5252954a1c01b539c5c9ecc0740ef8aca4ae2929 /sample-apps/react-todo
parent3297cbbd5d3b8bc3cbedbc294dd1f70273e8e8fb (diff)
Roll basic TODO with hooks (wowwwie)HEADmaster
Diffstat (limited to 'sample-apps/react-todo')
-rwxr-xr-xsample-apps/react-todo/src/app.js52
-rwxr-xr-xsample-apps/react-todo/src/index.js21
2 files changed, 41 insertions, 32 deletions
diff --git a/sample-apps/react-todo/src/app.js b/sample-apps/react-todo/src/app.js
index 7e261ca..4bb238c 100755
--- a/sample-apps/react-todo/src/app.js
+++ b/sample-apps/react-todo/src/app.js
@@ -1,28 +1,30 @@
-import React, { Component } from 'react';
-import logo from './logo.svg';
-import './App.css';
+import React, { useState, useEffect } from 'react'
-class App extends Component {
- render() {
- return (
- <div className="App">
- <header className="App-header">
- <img src={logo} className="App-logo" alt="logo" />
- <p>
- Edit <code>src/App.js</code> and save to reload.
- </p>
- <a
- className="App-link"
- href="https://reactjs.org"
- target="_blank"
- rel="noopener noreferrer"
- >
- Learn React
- </a>
- </header>
- </div>
- );
+import './app.css'
+
+export default function App(db) {
+ const [todoText, setTodoText] = useState('')
+ const [todoList, setTodoList] = useState([])
+ const addTodo = text => {
+ setTodoList([...todoList, text])
}
+ return (
+ <div>
+ <form>
+ <label>Todo</label>
+ <input
+ type="text"
+ name="todo"
+ onChange={e => setTodoText(e.target.value)}
+ value={todoText}
+ />
+ </form>
+ <button onClick={() => addTodo(todoText)}>Add Todo</button>
+ <ul>
+ {todoList.map(k => (
+ <li key={k}>{k}</li>
+ ))}
+ </ul>
+ </div>
+ )
}
-
-export default App;
diff --git a/sample-apps/react-todo/src/index.js b/sample-apps/react-todo/src/index.js
index 0c5e75d..c03cc2c 100755
--- a/sample-apps/react-todo/src/index.js
+++ b/sample-apps/react-todo/src/index.js
@@ -1,12 +1,19 @@
-import React from 'react';
-import ReactDOM from 'react-dom';
-import './index.css';
-import App from './App';
-import * as serviceWorker from './serviceWorker';
+import React from 'react'
+import ReactDOM from 'react-dom'
+import './index.css'
+import App from './app'
+import { dbFactory } from 'naive-client'
+import * as serviceWorker from './serviceWorker'
-ReactDOM.render(<App />, document.getElementById('root'));
+const httpUrl = 'http://localhost:5000'
+const wsUrl = 'ws://localhost:5001'
+const db = dbFactory({ wsUrl, httpUrl })
+
+db.init()
+
+ReactDOM.render(<App db={db} />, 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.
// Learn more about service workers: http://bit.ly/CRA-PWA
-serviceWorker.unregister();
+serviceWorker.unregister()