Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...