0

I have a generic button where I want to pass an icon as a component

 export const GenericButton = ({ name, type, iconType, text, primary }) => {
  return (
    <>
      <button
        className={primary ? 'genericButton_primary' : 'genericButton_secondary'}
        name={name}
        type={type}
      >
          <span className='genericButton_icon'>
            {iconType}
          </span>
        {text}
      </button>
    </>
  );
}

and here I have a parent in which I pass these components

import { ReactComponent as Google } from '../../common/g logo.svg';
import { ReactComponent as Fb } from '../../common/f logo.svg';

....

<GenericButton 
   name='gmail'
   type='button'
   text='Register with Google'
   iconType={<Google />}
  />
  <GenericButton 
    name='fb'
    type='button'
    text='Register with Facebook'
    iconType={<Fb />}
  />

As a result I get two buttons with the same icon, why?

1

1 Answer 1

2
import { ReactComponent as Google } from '../../common/g logo.svg';
import { ReactComponent as Fb } from '../../common/f logo.svg';

....

<GenericButton 
   name='gmail'
   type='button'
   text='Register with Google'
   iconType={Google}
  />
  <GenericButton 
    name='fb'
    type='button'
    text='Register with Facebook'
    iconType={Fb}
  />


 export const GenericButton = ({ name, type, iconType, text, primary }) => {
  return (
    <>
      <button
        className={primary ? 'genericButton_primary' : 'genericButton_secondary'}
        name={name}
        type={type}
      >
          <span className='genericButton_icon'>
            <iconType />
          </span>
        {text}
      </button>
    </>
  );
}
Sign up to request clarification or add additional context in comments.

1 Comment

I copied your code, now the <iconType /> element is empty

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.