Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
TypeError: Cannot read properties of undefined (reading 'SOLDOUT')

I have been trying to fetch data without using setTimeout from getProducts function. The code fetches data once in 50 trials when I tried setTimeout function outside the useEffect. I am new to react and I am trying to refactor the code.

const Allproducts = (props) => {

  useEffect(() => {
  let getProductsData = setTimeout(() => props.getProducts(), 10);
        return() => {
    clearTimeout(getProductsData);
  };
 },[]);

    const { data } = props.security;
let productsData=[];
    if(productsData['SOLDOUT'] === "" || productsData['AVAILABLE'] === "") {
      productsData= <Loader />;
    }

  return(
    <div>
      <div>
        <h1 className="primary-header">Products</h1>
        <Broadcast/>
      </div>
            
      <Row>
        <Col>
          <Jumbotron id="allcards">
            <div className="card">
              <h2>{productsData['AVAILABLE']}</h2>
              <h6>Available</h6>
            </div>
          </Jumbotron>
        </Col>
        <Col>
          <Jumbotron id="allcards">
            <div className="card">
              <h2>{productsData['SOLDOUT']}</h2>
              <h6>Sold out</h6>
            </div>
          </Jumbotron>
        </Col>
      </Row>
    </div>
  )
}

const mapStateToProps = (state) => ({
  security: state.security,
});

export default connect(mapStateToProps, { getProducts })(AllProducts); 
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!