1

So I have this component name called "Technologies" where I'm using react-icons and passing it through props to different component name "Icon" or on a different page.

Technologies Page:

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;

And this is the Icon Page, where I'm receiving props data:

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>
        </>
    )
}
Golamrabbi Azad
  • 369
  • 1
  • 9
Deepak Ranga
  • 123
  • 1
  • 1
  • 9

2 Answers2

2

You can not directly accessible through import instead use **children**

Shubham Dhumal
  • 125
  • 1
  • 9
  • Here Technologie.js is a parent from where I'm sending props data and Icon.js is a child where I'm receiving data, but it requires react-icon name in import too.. where I'm facing difficulty – Deepak Ranga Aug 08 '21 at 18:17
  • with react-icon, you can not do directly look for material UI icons for react it will fit your scenario, or you want to use react-cons import icon in Technologies.js then import technologies.js as component in other componet – Shubham Dhumal Aug 08 '21 at 18:26
0

Solved It:

in Technologies.js :

import React from 'react';
import { IconContext } from "react-icons";
import * as Icons from 'react-icons/all';
import IconsData from './subcomponents/IconsData';

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">
                {IconsData.map((item, index) => {
                    return (
                        <div className="text-center" key={index}>
                            <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' } }}>
                                    {item.icon}
                                </IconContext.Provider>
                            </div>
                            <h6 className="mb-2 text-sm font-bold leading-5 tracking-wider uppercase">
                                {item.title}
                            </h6>
                        </div>
                    );
                })}

            </div>
        </div>
    );
};

export default Technologies;

And In IconsData.js :

import React from 'react'
import * as Icons from 'react-icons/all';

const IconsData = [
{
    title: 'Wordpress',
    icon: <Icons.ImWordpress />
},
{
    title: 'ReactJs',
    icon: <Icons.GrReactjs />
}
];

export default IconsData;

WORKED !!!

Deepak Ranga
  • 123
  • 1
  • 1
  • 9