From 6dd6ad0ec6f483008792a2d08f317288e0634967 Mon Sep 17 00:00:00 2001 From: Nick Van Doorn Date: Mon, 4 Mar 2019 03:03:39 -0800 Subject: Roll basic TODO with hooks (wowwwie) --- sample-apps/react-todo/src/app.js | 52 +++++++++++++++++++------------------ 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 ( -
-
- logo -

- Edit src/App.js and save to reload. -

- - Learn React - -
-
- ); +import './app.css' + +export default function App(db) { + const [todoText, setTodoText] = useState('') + const [todoList, setTodoList] = useState([]) + const addTodo = text => { + setTodoList([...todoList, text]) } + return ( +
+
+ + setTodoText(e.target.value)} + value={todoText} + /> +
+ + +
+ ) } - -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(, document.getElementById('root')); +const httpUrl = 'http://localhost:5000' +const wsUrl = 'ws://localhost:5001' +const db = dbFactory({ wsUrl, httpUrl }) + +db.init() + +ReactDOM.render(, 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() -- cgit v1.2.3