Created
April 19, 2023 18:38
-
-
Save yao3060/515e92c7c7fa4028396be28d9429a5f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 这一定有点用 | |
*/ | |
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