Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

211
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda