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

123
Views
re rendering using ref?

is there anyway I can force re-render a component using ref?

maybe something like this:

const CustomComp=React.memo(React.forwardRef(({...props},ref)=>{
  return(<View ref={ref} style={...}></View>);
}));

export default function App() {
  const Mainref=useRef();

  return(<View>
    <Pressable onPress={()=>{Mainref.TriggerRender()}}></Pressable>
    <CustomComp ref={Mainref}/>
  </View>);

}

that way if there are multiple sibling components with different refs
you wouldn't have to re-render all of them just to re-render one

is such a thing possible? or is there something similar to it?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can pass a callback to re-render the child component.

const CustomComp=React.memo(React.forwardRef(({...props},ref)=>{
  const [toggle, setToggle] = React.useState(false);
  function onUpdate() {
    // will trigger re-render
    setToggle(!toggle);
  }
  // set onUpdate on mount
  React.useEffect(() => { 
    if (ref.current) ref.current.onUpdate = onUpdate;
  });
  return(<View ref={ref} style={...}></View>);
}));

export default function App() {
  let Mainref=useRef();

  return(<View>
    <Pressable onPress={()=>{Mainref.current.onUpdate()}}></Pressable>
    <CustomComp ref={Mainref}/>
  </View>);

}

Better approach is to lift the state to a level higher in the component tree, or use a global state manager such as React context API in case the state does not belong in the App component.

const CustomComp=React.memo(React.forwardRef(({...props},ref)=>{
  return(<View ref={ref} style={...}></View>);
}));

export default function App() {
  let Mainref=useRef();
  const [toggle, setToggle] = React.useState(false);
  function onUpdate() {
    // will trigger re-render on the whole view
    setToggle(!toggle);
  }

  return(<View>
    <Pressable onPress={onUpdate}></Pressable>
    <CustomComp ref={Mainref}/>
  </View>);

}
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!