reactjs - 是否可以在反应导入中传递道具
问题描述
所以我有一个名为“Technologies”的组件名称,我正在使用react-icons
它并将它通过道具传递给不同的组件名称“图标”或不同的页面。
技术页面:
import Icon from './subcomponents/Icon';
const Technologies = () => {
return (
<div className="px-4 py-16 mx-auto sm:max-w-xl md:max-w-full lg:max-w-screen-xl md:px-24 lg:px-8 lg:py-20">
<div className="grid grid-cols-2 gap-5 row-gap-5 sm:grid-cols-3 lg:grid-cols-6">
<Icon name={AiFillAndroid}/>
</div>
</div>
);
};
export default Technologies;
这是图标页面,我在其中接收道具数据:
import { IconContext } from "react-icons";
import {props.name} from 'react-icons/all'; **// Here is the issue "Is it possible to receive props data like this"**
export default function Icon(props) {
return (
<>
<div className="text-center">
<div className="flex items-center justify-center w-10 h-10 mx-auto mb-4 rounded-full bg-indigo-50 sm:w-12 sm:h-12">
<IconContext.Provider value={{ style: { color: '#fff' } }}>
<{props.name} /> **// Here is the issue "Is it possible to receive props data like this"**
</IconContext.Provider>
</div>
<h6 className="mb-2 text-sm font-bold leading-5 tracking-wider uppercase">
World
</h6>
</div>
</>
)
}
解决方案
您不能通过导入直接访问,而是使用**children**
推荐阅读
- linux - 使用 Git 在 Linux 服务器上设置字符集
- angular - Angular 组件在 router.navigate 之后没有更新
- keras - 为什么我的 keras 模型返回的指标比我指定的多?
- java - 使用 401 状态码的新 Auth 标头重试 zuul 请求
- python - 在mongodb中锁定数据库以使用python编写(无线程)
- linux - 如何以蓝色邮寄消息正文 |Linux |
- java - 如何获取chrome浏览器Cookies并在IE浏览器中使用
- javascript - Redux 没有正确调用动作
- python - 如何使用嵌套循环但每次循环时将值增加 2
- codeigniter-3 - 如何在 Codeigniter 中分离公共模块和管理模块?