Refreshing View on React State Change #2691
-
Hi JBrowse devs! I'm working on using an inline instance of JBrowse2 in a React page. I have a list of features available in a React state variable, and I'd love to have one of my tracks get redrawn as the state changes. I've been able to load in features from the state through a FromConfigAdapter, but I'm struggling to create a dynamic view - even though I can tell that the state variable is updating, the track is not redrawn. Here's the general idea of what I've tried, using the following adapter in a BasicTrack with an SvgFeatureRenderer:
The rendering is successful (though static) if I prepopulate the state variable by calling createFeaturesFromSegments in the first line, and a console.log in the useEffect function shows the features updating in my state. Therefore, I'm thinking it's a matter of not being able to trigger a redraw in JBrowse with the new features. I can dynamically load the data from a remote URL through a custom BaseFeatureDataAdapter, but given that I already have the data locally I'm a bit loathe to pull it down again and duplicate other client side transformations. Any guidance you could give here as to whether this is possible and how to proceed? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
You should be able to get the track to update dynamically, but it'll have to be approached in a bit different way. The adapter in a track gets read once when JBrowse starts and populates its internal state, but then isn't used after that. That's why changing the adapter like that doesn't work, since it's already been read. You can, however, update the internal state that gets created. Here's an example function that should add a feature to a FromConfigAdapter: function addFeature(newFeature) {
const currentFeatures = [
...viewState?.config.tracks[0].adapter.features.value,
]
currentFeatures.push(newFeature)
viewState?.config.tracks[0].adapter.features.set(currentFeatures)
} In this function, |
Beta Was this translation helpful? Give feedback.
You should be able to get the track to update dynamically, but it'll have to be approached in a bit different way. The adapter in a track gets read once when JBrowse starts and populates its internal state, but then isn't used after that. That's why changing the adapter like that doesn't work, since it's already been read.
You can, however, update the internal state that gets created. Here's an example function that should add a feature to a FromConfigAdapter:
In…