我希望我能把所有的图像都放到“Image.jsx”文件中,并轻松地将它们从 React 中的另一个文件中取出
例如
export const Header = ({ title, children }) => {
return (
<>
<Title>{title}</Title>
<Items>{children}</Items>
</>
);
};
Header.propTypes = {
title: PropTypes.node,
children: PropTypes.object,
};
// I made a separate component. And the codes in the component will be used in other files.
import { Header } from "../BaseLabel";
const FriendstHeader = () => {
return (
<>
<FriendContainer>
<Header title="친구" style={{ color: "#191919" }}/>
</FriendContainer>
</>
);
};
export default FriendstHeader;
我想管理图像。像这个例子。这是 Image.jsx
import React from 'react';
import PropTypes from 'prop-types';
import Search from "images/search.png";
const imageSrc = [ Search ];
export const Image = (props: imageSrc) => {
return (
<>
<img alt="">{imageSrc.Search}</img>
</>
);
};
Image.propTypes = {
imageSrc: PropTypes.node,
};
这是将显示图像的主屏幕。
import React from 'react';
import Search from "images/search.png";
const Header = () => {
return(
<>
<Items>
<img src={Search} width="18px" height="18px" alt="" />
</Items>
</>
)
}
export default Header;
图片其实不是一张,只是为了不显得复杂,就简化为上面一张。