awesome-ocap icon indicating copy to clipboard operation
awesome-ocap copied to clipboard

encapsulation (for ocaps) in react? Web Components?

Open dckc opened this issue 4 years ago • 1 comments

@Bill-Keuntje @jimscarver @David405 IOU something more coherent, but...

the following is what happened when I told some folks knoweldgeable about ocap and react "I tried to use react but I couldn't figure out how to encapsulate state". Somehow the problem melted away:

import { useState } from 'react';

const { freeze } = Object;

function counterComponent({ start }) {
  const [v1, setState] = useState(1);

  const value = v1;
  const incrButton = freeze(html`
    <button onClick=${setState(value + 1)}></button>
  `);
  const decrButton = freeze(html`
    <button onClick=${setState(value - 1)}></button>
  `);

  return freeze(
    () =>
      html`
        <div>${value}</div>
      `,
  );
}

dckc avatar Jun 23 '21 02:06 dckc

Interesting. actix-web (Rust) has a similar construct that we use in Confidios to allow multiple blockchain REST operations without having to approve every single request.

Bill-Kunj avatar May 26 '25 22:05 Bill-Kunj