Solving Issue with Finding 3 Random Questions Efficiently

Solving Issue with Finding 3 Random Questions Efficiently
Slide Note
Embed
Share

In a problem scenario where a loop runs until a certain condition is met to find 3 random questions, a potential solution is to limit the loop iterations using a counter mechanism. By setting a counter to restrict the loop to a reasonable number of runs, like 150, the process becomes more efficient and prevents exceeding free reads from Firebase. Additionally, the use of useRef Hook in React can help manage mutable reference objects effectively for state management in components.

  • Efficiency
  • Loop Iterations
  • Counter Mechanism
  • useRef Hook
  • React Components

Uploaded on Mar 09, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Ask Ouija App-Lab By: Dr. Taha Havakhor Assistant Professor of MIS

  2. A problem with finding 3 random questions The loop will run until the while condition is true Can logically exceed 50k free reads from Firebase if it does not find at least 3 questions Let s fix it!

  3. Solution? Set a counter to make sure the loop won t run for more than a limited number- for finding 3 random questions 150 runs is more than enough! Class discussion: Why can t we use a local variable or a state variable?

  4. useRef Hook const refContainer = useRef(initialValue); useRef returns a mutable ref object whose .current property is initialized to the passed argument (initialValue). Essentially, useRef is like a box that can hold a value in its .current property. To get and change the value you must reference refContainer.current

More Related Content