当我在浏览器中查看页面中的组件(ElementTile)时,它们会转换为div。适用于“ElementTile”的CSS规则也不起作用(当然,这是意料之中的,因为它们被更改为div)为什么会这样?我可以改变这种行为吗?
谢谢你提前!
page.tsx:
import React from 'react';
import ElementTile from '@app/components/ElementTile/ElementTile';
import { elements } from '@public/libraryChemistry';
import { useLanguageData } from '@data/languageLoader';
import PSEFilter from '@app/components/PSEFilter/PSEFilter';
const Projects: React.FC = () => {
const data = useLanguageData("periodicTable");
return (
<main className='mx-auto max-w-9xl mt-40 md:mt-20 lg:mt-24'>
<PSEFilter/>
<div className="grid grid-cols-18 grid-rows-9 gap-0 sm:gap-1 lg:gap-2 xl:gap-4">
{/* Line Number 1 */}
<ElementTile className='bg-cyan-500' elementData={elements[0]} />
<ElementTile className='bg-purple-500 col-start-18' elementData={elements[1]} />
{/* Line Number 2 */}
<ElementTile className='bg-red-500' elementData={elements[2]} />
...
字符串
ElementTile.tsx:
import { ElementData } from '@public/libraryChemistry';
import React, { useState } from 'react';
import ElementPopUp from '../ElementPopUp/ElementPopUp';
interface ElementTileProps {
elementData?: ElementData;
className?: string;
}
const ElementTile: React.FC<ElementTileProps> = ({ elementData, className }) => {
const [isPopUpVisible, setIsPopUpVisible] = useState(false);
const togglePopUp = () => {
setIsPopUpVisible(!isPopUpVisible);
};
return (
<div
className={`flex aspect-square cursor-pointer text-center items-center justify-center duration-300 text-xs md:text-xl xl:text-2xl text-black p-1 md:p-2 xl:p-4 border-[#404040] sm:border-2 hover:border-4 hover:z-10 hover:border-black p-auto ${className}`}
onClick={() => {
if (elementData) {
togglePopUp();
}
}}
>
{elementData ? elementData.kurzsymbol : '↓'}
{isPopUpVisible && (
<ElementPopUp onClose={togglePopUp} elementData={elementData} />
)}
</div>
);
};
export default ElementTile;
型
正如你所看到的,没有ElementTile的了,只有div的:
x1c 0d1x的数据
1条答案
按热度按时间zfciruhq1#
组件'ElementTile'包含一个div作为它的父标签。所以你能看到的只是元素和分配给它的className属性。这是React JSX的自然行为。