简体   繁体   English

react-icons 设置子图标的大小道具

[英]react-icons set size prop of Icon in child

What I would like to do but isn't possible is something like this:我想做但不可能的事情是这样的:

import { FaBook } from 'react-icons/fa';

const Parent = () => <Child icon={FaBook}>Save</Child>;

Then in the child然后在孩子

const Child = ({ icon }) => (
  <div>
    <Icon as={icon} size={20} />
    <Icon as={icon} size={30} />
  </div>
);

This is so I don't have to pass an iconSmall and iconLarge prop separately the size is the only differentiator.这样我就不必分别传递iconSmalliconLarge道具,尺寸是唯一的区别。 I there a react way I can add the size property on the child?我有一种反应方式可以在孩子身上添加size属性吗?

Whatever the Icon component is.无论 Icon 组件是什么。 Something like this?像这样的东西?

Parent.js父.js

import React from 'react';
import {FaBook} from 'react-icons/fa';
import Child from './Child';

const Parent = () => <Child icon={FaBook}>Save</Child>;

export default Parent;

Child.js Child.js

import React from 'react';

const Child = ({icon}) => (
    <div>
        {icon({size: 20})}
        {icon({size: 30})}
    </div>
);

export default Child;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM