Skip to content

Instantly share code, notes, and snippets.

@yao3060
Created April 19, 2023 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yao3060/515e92c7c7fa4028396be28d9429a5f3 to your computer and use it in GitHub Desktop.
Save yao3060/515e92c7c7fa4028396be28d9429a5f3 to your computer and use it in GitHub Desktop.
/**
* 这一定有点用
*/
import { useEffect, useRef, useState } from "react";
export default function Header() {
const attrs = useRef(
new Map(
Object.entries({
k_c: "89e39910e91",
k_a: "89e39910e91",
})
)
);
const [selected, setSelected] = useState({});
useEffect(() => {
setSelected(Object.fromEntries(attrs.current));
}, []);
return (
<div>
<button
onClick={() => {
const string = Math.random().toString(16);
attrs.current.set("k_" + string.substring(3, 2), string.substring(4));
setSelected(Object.fromEntries(attrs.current));
}}
>
Add random key pair
</button>
<pre>{JSON.stringify(selected, undefined, 2)}</pre>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment