Need to store and access values on an array in react. So far I found solutions that uses filters or does not fit my requirements.
Just need to push a string value with string key, and retrieve it with same key. How to do it?
Code:
import "./styles.css";
import { useRef } from "react";
export default function App() {
const Presence = useRef({});
function objTest() {
Presence.current.length = 0;
const uid = "UID1"; //Date.now().toString();
//let obj = { [uid]:{ presence: "Busy"} };
let obj = { [uid]: "Busy" };
Presence.current.push(obj);
console.log(Presence.current, " , ", Presence.current[uid]);
}
return (
<div className="App">
<h1>Hello CodeSandbox</h1>
{objTest()}
</div>
);
}