1

I'm having a hard time trying to achieve this approach:

I have to add a super index number only in some list items depending on their ID.

What I is when product with id 198940 and 20084 both exist will render 198940 with superIndex 1 and 20084 with superIndex 2.

In the case that only id 198940 exist id 198940 will have superIndex 1 In the case that only id 20084 exist 20084 will have superIndex 1.

At the moment Only works when Both ID'S exist and also when only id 198940 exist.

Here's where I got the logic:

  /**
   *  Component constructor.
   */
  constructor(props) {
    super(props)





    this.state = {
      active: false,
      superIndex1: null,
      superIndex2: null



    }

  }

  componentDidMount() {
    const { activeUserProducts } = this.props;
    let index1 = null;
    let index2 = null;
  
    if (activeUserProducts.products.some(p => p.id === 198940)) {
      index1 = 1;
      if (activeUserProducts.products.some(p => p.id === 20084)) {
        index2 = 2;
      }
    } else if (activeUserProducts.products.some(p => p.id === 20084)) {
      index1 = 1;
    }
  
    this.setState({
      superIndex1: index1,
      superIndex2: index2
    });
  } ```    

And I need to render it in a child component where I pass superIndex1 and superIndex2 as props:
<h4 className='wallets__table__label wallets__table__label--xxl'>
                          {product.title} 
    {product.id === 198940 && props.superIndex.superIndex1 && <sup>{props.superIndex.superIndex1}</sup>}
    {product.id === 20084 && props.superIndex.superIndex2 && <sup>{props.superIndex.superIndex2}</sup>}
```

Hope you guys can help me , I've been trying all day to get this done. Thanks!

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.