React's useImperativeHandle with practical example | by ByteCode Pandit
Hi, all techies today we are going to discuss the react's important hook useImperativeHandle. What it solved for me When I was working on a react-native project, there was a situation when I have to toggle the modal view. So for that, I just took another boolean state in the parent component and changed it. import React , { useState } from 'react' ; import { Pressable , Text , View } from 'react-native' ; export const ParentComponent = ( props : any ) => { const [ showModal , setShowModal ] = useState < boolean >( false ); const toggleModal = ( value : boolean ) => { setShowModal ( value ); } return < View > < Pressable onPress = { () => toggleModal ( true ) } >< Text > Show Modal </ Text ></ Pressable > { showModal && < ModalComponent /> } </ View > } But because as we know whenever we change the state of the component it gets rerender wh...