diff options
author | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 03:03:39 -0800 |
---|---|---|
committer | Nick Van Doorn <vandoorn.nick@gmail.com> | 2019-03-04 03:03:39 -0800 |
commit | 6dd6ad0ec6f483008792a2d08f317288e0634967 (patch) | |
tree | 5252954a1c01b539c5c9ecc0740ef8aca4ae2929 /sample-apps/react-todo | |
parent | 3297cbbd5d3b8bc3cbedbc294dd1f70273e8e8fb (diff) |
Diffstat (limited to 'sample-apps/react-todo')
-rwxr-xr-x | sample-apps/react-todo/src/app.js | 52 | ||||
-rwxr-xr-x | sample-apps/react-todo/src/index.js | 21 |
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() |