Closed naporin0624 closed 11 months ago
useEffect
fires after the initial render, meaning the store will be initialised too late. If you use useEffect
you'll now have two renders, one where no routes are rendered and then a second once the store is initialised.
Thank you for taking a look.
It was good to learn more about why you are running side effects in useMemo.
Motivation
This PR proposes a modification in the interaction between the singleton "RouteStore" and React. Currently, the
useMemo
hook is being utilized, which is typically used for caching values (useMemo documentation). This PR suggests that theuseEffect
hook might be more suitable for this context, as detailed in its documentation.Execution
To realize the proposed change, i undertook the following steps:
global-state.tsx
file to facilitate the mocking of the store singleton, which was challenging withjest.mock
.useMemo
touseEffect
inuseInitializeExpoRouter
to ensure alignment with the proposed integration strategy.useInitializeExpoRouter
post-modification.Test Plan
To substantiate these modifications, a comprehensive test plan has been devised. The testing strategy underscores:
store.initialize
function is initiated exclusively when alterations occur in the context or location, reinforcing the stability and efficiency of the system.useExpoRouter
function to maintain seamless connectivity and functionality.The following strategies were employed during the testing phase:
store.initialize
function was monitored to ensure it is called when there is a change in reference and context, further validated by rerendering with new context and location values.store.initialize
function is not called repetitively when the same context is passed, fostering system efficiency.These strategies were systematically executed using the
renderHook
function alongside the implementation of mock functions to mimic the behavior of thestore.initialize
andstore.subscribeToStore
methods, thereby offering a robust and reliable testing framework.