Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.4k views
in Technique[技术] by (71.8m points)

reactjs - Redux does not delete some UI items after state update

I am having such an issue when there are two modes of presenting UI elements in Redux. When switching between them one element is left off from one mode each time the mode switched back and forth (using a toggle). Here is the main UI that I have:

const Variants = React.memo(({ variants, ...props }) => (
  <Grid stackable divided="vertically" columns="equal">
    {variants.map(variant => (Array.isArray(variant) ?
      <CompoundHets variants={variant} key={`${variant.map(v => v.variantId).join()}-${variant[0].familyGuids.join('-')}`} {...props} /> :
      <Variant variant={variant} key={`${variant.variantId}-${variant.familyGuids.join('-')}`} {...props} />
    ))} 
  </Grid>
))

Variants.propTypes = { 
  variants: PropTypes.array,
}

export default Variants

So, variants can be just an array of objects or an array of arrays and these two cases correspond to two different modes switched by the check - Array.isArray(variant). So, what happens is:

  1. Initially CompoundHets component gets rendered correctly (array of arrays case)
  2. Switching the mode (passing different variants parameter) leaves off 1 CompoundHets and renders all of the Variant components
  3. Repeating 1 and 2 leaves off now 2 CompoundHets.

I have no idea why it's behaving like that since I checked and variants is passed off perfectly correct type each time and the state does update with the correct data. And no matter what I have inside Variant or CompoundHets it should draw one or the other not leaving the traces of one or the other.

For further reference if anyone is interested to dig into CompoundHets or Variant elements:

https://github.com/broadinstitute/seqr/blob/master/ui/shared/components/panel/variants/Variants.jsx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...