App.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { useState, useEffect } from 'react'
  2. import reactLogo from './assets/react.svg'
  3. import viteLogo from '/vite.svg'
  4. import './App.css'
  5. import {createPub, usePub} from './lib';
  6. import type { Pub } from './lib';
  7. const testPub:Pub = createPub({count: 0})
  8. testPub.subscribe(() => console.log(testPub.count))
  9. setInterval(() => testPub.count--, 5000)
  10. function App() {
  11. const {count} = usePub(testPub)
  12. return (
  13. <>
  14. <div>
  15. <a href="https://vitejs.dev" target="_blank">
  16. <img src={viteLogo} className="logo" alt="Vite logo" />
  17. </a>
  18. <a href="https://react.dev" target="_blank">
  19. <img src={reactLogo} className="logo react" alt="React logo" />
  20. </a>
  21. </div>
  22. <h1>Vite + React</h1>
  23. <div className="card">
  24. <button onClick={() => testPub.count++}>
  25. count is {count}
  26. </button>
  27. <p>
  28. Edit <code>src/App.tsx</code> and save to test HMR
  29. </p>
  30. </div>
  31. <p className="read-the-docs">
  32. Click on the Vite and React logos to learn more
  33. </p>
  34. </>
  35. )
  36. }
  37. export default App