Change in view location and useState #4265
Unanswered
adampowell1astrazeneca
asked this question in
Q&A
Replies: 1 comment 7 replies
-
hi there, without memoizing, the view state will be 'reset' on each re-render which will be very slow which is what you were seeing most likely example code change
it's a little technical but the above uses 'useMemo' but there are other approaches (useEffect+setState, useRef, and useState callback all). there are a bunch of methods with different uses and needs. see for example here https://tkdodo.eu/blog/use-state-for-one-time-initializations |
Beta Was this translation helpful? Give feedback.
7 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently doing something like this previous post (#2544). I want to use the current viewed location to do some filtering on results in a separate component (i.e. a table showing the results that are visible in the JBrowse component). I'm using the
onChange
approach. I've also tried the mobxobserve
way and hit similar problems.In general, this is all fine if I give it a trivial function (e.g.
console.log
). However, once I give it the state update function fromuseState
, the JBrowse component resets (nearly) every time the visible region is changed (either by dragging or zooming). Am I missing something in the approaches? Looking at the React profiler, it's not immediately obvious if its the actual component being redrawn or if it's something happening within JBrowse itself. Any insight would be great. Thanks!Reduced example:
Parent component:
JBrowseInstance
where I'm runningcreateViewState
.Beta Was this translation helpful? Give feedback.
All reactions