I guess I found the root cause of the inconsistent behavior. There is another hook called useLayoutEffect
useLayoutEffect The signature is identical to useEffect, but it fires synchronously after all DOM mutations. Use this to read layout from the DOM and synchronously re-render. Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.
the useLayoutEffect will block the painting while the useEffect will not. That confirm and explains my guess that the didFocus event had fired, but it didn't trigger the listener since it miss the timing
so in my case, I have to use useLayoutEffect instead of useEffect
- React navigation didfocus event listener works differently between class component and functional component
- React custom hook with event listener not works while updating the state
- React Navigation "focus" event listener does not use updated value
- this inside react class component works differently
- Add Event Listener to items by Class in React
- Event Listener on Navigation with react router v6
- Wrong React hooks behaviour with event listener
- Remove Event Listener On Unmount React
- React Navigation V2: Difference between navigation.push and navigation.navigate
- React setState hook from scroll event listener
- Removing event listener in React (lodash.throttle)
- React hooks value is not accessible in event listener function
- Using transitionend event listener with react to create a transition
- Unsubscribe from event listener react hooks
- How does React router works and what is the difference between <link> and<Route>
- React navigation event listeners being called multiple times
- What is the difference between arrow functions and regular functions inside React functional components (no longer using class components)?
- adding event listener for keydown to react element
- Remove event listener manually react hooks
- React JS: Differentiate between Click and Click + Shift event
- Performance comparison between react hooks and react class
- onDeviceReady event listener in react component
- React Native - Global Event Listener
- What’s the difference between React event and DOM event?
- React event.target is not the element I set event Listener on
- React Native Stack Navigation With Class Component
- Event listener functions changing when using React hooks
- how to use react devtools to get function tied to an onClick event listener
- How can I use react navigation props in class component?
- React Warning non-passive event listener to a scroll-blocking 'touchstart'
More Query from same tag
- Dynamic Form with Radio Button in Ant Design
- I am getting a "SyntaxError: invalid syntax" when I am trying to install React Slingshot
- Recharts is not working for the React with typescript
- Functions are not valid as a React child when lazy loading
- React screen size if condition returns undefined
- How can I create a clickable first option in Material UI Labs Autocomplete
- Google maps marker size with react
- Passing Event from Parent to Child-Child
- Change Color of Icon in React
- The tag <ReactComponent> is unrecognized in this browser
- wizard form - react final form
- How override a Button Ant Design with styled component and typescripts?
- ReactJS TypeError: Cannot read property 'push' of undefined
- Axios to Node (Express) GET Request
- How to have a custom internal server error using react next? (500 internal server error)
- ReactJS: How to make button background colour change when the text inside it is a certain value
- React .js.jsx extension in Ruby on Rails application
- In React a div has an height of a zero, then why its children are still showing on the screen
- match.params returns empty even when URL contains params
- How to send array of objects data from child component to parent component and store in the parent object using react hooks?
- Dispatch action when component is created
- react-scripts build "Parse error on line 1"
- Setting coordinates from openstreetmap as state
- Floating Action Button not sticked to its parent element
- How do I convert componentDidMount() and componentWillUnmount to the useEffect()?
- webpack-dev-server Cannot find module 'webpack'
- Close sidebar with react in combination with react-state
- How should child components in React communicate between each other in a clean and maintainable fashion?
- Getting a Certificate error when making a GET request in a VS Code extension webview
- I can not get data from this.state