Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
propTypes debe ser una advertencia de consola funcional al pasar una matriz de iconos

Tengo el siguiente componente,

 import React from 'react'; import PropTypes from 'prop-types'; import * as HIcons from '@heroicons/react/outline'; export default function Button({ type, variant, icon, label }) { const { ...icons } = HIcons; const TheIcon = icons[icon]; return ( <div> <button type={type} className={['btn', `btn--${variant}`].join(' ')}> <TheIcon className="w-4 h-4 mr-2" /> {label} </button> </div> ); } Button.propTypes = { type: PropTypes.string.isRequired, label: PropTypes.string.isRequired, icon: PropTypes.oneOf[Object.keys(HIcons)], variant: PropTypes.oneOf(['sm', 'md', 'lg']) }; Button.defaultProps = { type: 'button', label: 'Submit', icon: 'SaveIcon', variant: 'md' };

y tengo el siguiente archivo de cuentos

 import Button from '.'; import * as HIcons from '@heroicons/react/outline'; const { ...icons } = HIcons; export default { title: 'Components/Buttons', component: Button, argTypes: { type: { options: ['button', 'submit', 'reset'], control: { type: 'select' } }, icon: { options: Object.keys(icons), control: { type: 'select' } } } }; const Template = (args) => <Button {...args} />; export const Small = Template.bind({}); Small.args = { label: 'Small', variant: 'sm', icon: 'SaveIcon' };

Por lo que sé, estoy pasando todo correctamente, puedo cambiar los íconos y otras cosas, sin embargo, aparece el siguiente error de consola

 Warning: Failed prop type: Button: prop type `icon` is invalid; it must be a function, usually from the `prop-types` package, but received `undefined`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.

Cualquier ayuda para resolver esta advertencia sería genial ya que soy nuevo en propTypes.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

cambia tus proptypes a esto

 Button.propTypes = { type: PropTypes.string.isRequired, label: PropTypes.string.isRequired, icon: PropTypes.oneOf(Object.keys(HIcons)), variant: PropTypes.oneOf(['sm', 'md', 'lg']) };

por error escribes este:

 icon: PropTypes.oneOf[Object.keys(HIcons)],
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!