Use

  1. import { define, render } from 'omi'
  2. define('my-counter', function() {
  3. const [count, setCount] = this.use({
  4. data: 0,
  5. effect: function() {
  6. document.title = `The num is ${this.data}.`
  7. }
  8. })
  9. const [items, setItems] = this.use({
  10. data: [{ text: 'Omi' }],
  11. effect: function() {
  12. console.log(`The items count is ${this.data.length}.`)
  13. }
  14. })
  15. return (
  16. <div>
  17. <button onClick={() => setCount(count - 1)}>-</button>
  18. <span>{count}</span>
  19. <button onClick={() => setCount(count + 1)}>+</button>
  20. <ul>
  21. {items.map(item => {
  22. return <li>{item.text}</li>
  23. })}
  24. </ul>
  25. <button onClick={() => setItems([...items, { text: 'new item' }])}>
  26. add
  27. </button>
  28. <button onClick={() => setItems([])}>empty</button>
  29. </div>
  30. )
  31. })
  32. render(<my-counter />, 'body')