新手在这里,抱歉的愚蠢的问题:)
我该怎么把“钥匙”这个 prop 放到这个函数里呢?
代码是在上面的接触阴影。我尝试了很多方法,但所有的方法,我尝试了工作不正常。你能请检查,并告诉我如何把“关键”的 prop ?
import React, { Suspense, useEffect, useMemo, useRef, useState } from "react";
import "./PartOne.css";
const PartOne = () => {
const [rooms, setRooms] = useState([
Room1,
Room2,
Room3,
Room4,
Room5,
Room6,
Room7,
Room8
]);
useEffect(() => {
console.log("rooms state:", rooms);
}, [rooms]);
return (
<div className="wrapper">
{rooms.map((room, roomIndex) =>
room({ position: positions[roomIndex] })
)}
</div>
);
};
export default PartOne;
谢谢
1条答案
按热度按时间ghg1uchk1#
你可以将
room
函数中的元素 Package 在<React.Fragment>
中,并将key
赋给它: