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

React three fiber passing function arguments

I made a function to return a material based on a value

function MyMat(height){

  if(height > 2) {
    return (<meshStandardMaterial color="#878787" flatShading={true} />)
  } 
  else if(height > 1) {
    return (<meshStandardMaterial color="#674942" flatShading={true} />)
  }

  return (
    <meshStandardMaterial color="black" flatShading={true} />
  )
}

and when I call it in my canvas likes this

<MyMat height = {4} />

it works but the the value 4 (height) isn’t passed, how can I pass it?

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 need to write height as object props, not as a value.
Replace MyMat(height) with MyMat({height})

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