DEV Community

artydev
artydev

Posted on

Satefull components with UMAI

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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

👋 Kindness is contagious

DEV is better (more customized, reading settings like dark mode etc) when you're signed in!

Okay