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

109
Views
Accessing props func outside of the React components

I'm using an npm called react-zoom-pan-pinch which has multiple func as props. but I want to call some of them outside of the component. how can I call the component functions in my own function?

const handleShiftClick = () => {
    if (event.shiftKey) {
      zoomOut();// component function
    }
};

return (
    <div className="App">
      <TransformWrapper initialScale={1}>
        // functions
        {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
          <>
            <div className="tools">
              <Hotkeys keyName={keys.ZOOM_IN} onKeyDown={() => zoomIn()}>
                <button onClick={() => zoomIn()}>+ key</button>
              </Hotkeys>
            </div>

            <TransformComponent></TransformComponent>
          </>
        )}
      </TransformWrapper>
    </div>
  );
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

const transformRef = useRef(null);
const handleShiftClick = () => {
    if (event.shiftKey) {
      transformRef.current?.zoomOut();// component function
    }
};
return (
    <div className="App">
      <TransformWrapper initialScale={1} ref={transformRef}>
        {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
          <>
            <div className="tools">
              <Hotkeys keyName={keys.ZOOM_IN} onKeyDown={() => zoomIn()}>
                <button onClick={() => zoomIn()}>+ key</button>
              </Hotkeys>
            </div>

            <TransformComponent></TransformComponent>
          </>
        )}
      </TransformWrapper>
    </div>
  )

TransformWrapper support forwardRef

about 4 years ago · Juan Pablo Isaza Report

0

You can pass them to a outer function.

const manageKeyPress = (funcs) => {
    return (event) => {
        const {zoomIn, zoomOut, resetTransform} = funcs;
        if(event.shiftKey) {
           zoomOut();
        }
    }

};

return (
    <div className="App">
      <TransformWrapper initialScale={1}>
        // functions
        {({ zoomIn, zoomOut, resetTransform, ...rest }) => (
          <>
            <div className="tools">
              <Hotkeys keyName={keys.ZOOM_IN} onKeyDown={manageKeyPress({zoomIn, zoomOut, resetTransform})}>
                <button onClick={() => zoomIn()}>+ key</button>
              </Hotkeys>
            </div>

            <TransformComponent></TransformComponent>
          </>
        )}
      </TransformWrapper>
    </div>
  );
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!