awesome-ocap
awesome-ocap copied to clipboard
encapsulation (for ocaps) in react? Web Components?
@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>
`,
);
}
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.