0

I have an icon.js file as shown below to export the icons of your need:

import RotateLeftIcon from '@material-ui/icons/RotateLeft';

const iconTypes = {
  LEFT_ROTATION: <RotateLeftIcon />,
};

export const iconNames = {
  LEFT_ROTATION: 'LEFT_ROTATION',
};

export const getIcon = (iconName, props) => {
  const Component = iconTypes[iconName];
  return <Component style={{ ...props }} />;
};

and I call them like this:

import React from 'react'

export default function TestingIcons() {
    return getIcon(iconNames.LEFT_ROTATION, {
        color: '#fff',
        fontSize: '1rem',
      });
}

When I do the above, I get this error: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

How to fix this?

1 Answer 1

1

You have to edit with the following:

const iconTypes = {
  LEFT_ROTATION: RotateLeftIcon,
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.