0.3.1 • Published 1 year ago

@ivi/identity v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

ivi Identity

Identity component is used to reset internal state.

Example

import { createRoot, update, component, useState, useEffect } from "ivi";
import { htm } from "@ivi/htm";
import { Identity } from "@ivi/identity";

const Timer = component((c) => {
  const [time, setTime] = useState(c, 0);

  useEffect(c, () => {
    const t = setInterval(() => {
      setTime(time() + 100);
    }, 100);
    return () => { clearInterval(t); };
  })();

  return () => time();
});

const App = component((c) => {
  const [key, setKey] = useState(c, 0);

  const onClick = () => { setKey(key() + 1); };

  return () => (
    htm`
    <div class="App">
      <button @click=${onClick}>Next</button>
      ${Identity({ key: key(), children: Timer() })}
    </div>
    `
  );
});

update(
  createRoot(document.body),
  App(),
);
0.3.1

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.0

1 year ago