我不知道如何在地图中添加参考。我尝试过这个东西,但是根本不起作用。
import React, { useRef } from "react";
import ReactDOM from "react-dom";
import "./styles.css";
function App() {
let numRef = useRef([]);
const mat = [1, 2, 3, 4, 5];
console.log(numRef); //
return (
<div className="App">
<div>
{mat.map((element, idx) => (
<p ref={numRef.current[idx]} type="text">
{element}
</p>
))}
</div>
</div>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Run Code Online (Sandbox Code Playgroud)
我想在每个p标签中提供所有不同的ref。
有时我使用JavaScript或MongoDB,可以看到如下代码: ({})
例如下面的代码行:
db.users.find({})
Run Code Online (Sandbox Code Playgroud)
但我不知道这到底意味着什么。你能告诉我那是什么吗?