Satefull components with UMAI
artydev

artydev @artydev

Joined:
Jul 17, 2019

Satefull components with UMAI

Publish Date: Mar 19
0 0

Demo

Look Ma, no tricky hooks, nice.

import { m, mount} from "umai";

let counters = [];

const Count = ({ initialCount }) => {
  let count = initialCount || 0;
  let inc = () => { count += 1  };
  return () => (
    <div>
      <h1>Count: {count}</h1>
      <button class="button" onclick={inc}>increment</button>
    </div>
  );
};


const App = () => <div>
  {counters.map(m)}
</div>;

mount(document.body, App);

counters.push(Count);
counters.push(Count({initialCount:1})) 
counters.push(Count({initialCount:2})) 
counters.push(Count({initialCount:3})) 
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment