Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

in react to reference component properties not defined as arguments?

export default function SoftMount({
  children,
  child_ref,
  real_class_name,
  duration,
}) {
  
  return <div/>
}

usage:

<SoftMount unexpected_prop={"some_value"} />

Inside of <SoftMount />, how do I access unexpected_prop?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can capture all remaining properties using the "rest parameters" sytax (...variable_name)

export default function SoftMount({
  children,
  child_ref,
  real_class_name,
  duration,
  ...other_props // This will collect all other props not destructured
}) {
  console.log(other_props.unexpected_prop); // "some_value"

  return <div/>
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading