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

208
Views
calling React function from another script and render it in Canvas

it's been weeks since i started this fun project..

and i think it's about time i tidy up a bit.

so i have this function that renders 3d models into canvas

main.jsx


   const [clothesCurrent, clothesModel] = useState("cModel1");

   const cModels = {

        cModel1: <C1 />,
        cModel2: <C2 />,
    }
    const CChange1 = () => {
        clothesModel("cModel1");
    }
    const CChange2 = () => {
        clothesModel("cModel2");
    }

  return(
    <div>

      <h3>Change Clothes</h3>
      <button onClick={CChange1}>Clothes1</button>
      <button onClick={CChange2}>Clothes2</button>
      <Canvas>
        <Suspense>
          {cModels[clothesCurrent]}
        </Suspense>
      </Canvas>
    </div>
  )


but then i create navbar and decided to migrate all the function there, with a simple minded thought i does it like this

Navbar.jsx

  <DropdownItem leftIcon={<BoltIcon />} onClick={<CChange1 />}>Hair 1</DropdownItem>
  <DropdownItem leftIcon={<BoltIcon />} onClick={<CChange2 />}>Hair 2</DropdownItem>

but this just wrong, and have tried modify const cChange to export function CChange() outside the main function and it still wont work. can you guys give me solution? thank you!

about 4 years ago · Juan Pablo Isaza
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!