Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maybe replace while loop with a slice/map #36

Open
oliverjam opened this issue Jun 9, 2022 · 0 comments
Open

Maybe replace while loop with a slice/map #36

oliverjam opened this issue Jun 9, 2022 · 0 comments

Comments

@oliverjam
Copy link

while (numCluesShown < Number(quizLength)) {

There's nothing wrong with your while loop (especially since it works), but it might be a little simpler to reason about a more standard array .map (since that's more "idiomatic" React). If you only want to render a certain number of things from the array the simplest solution might be to slice the array before mapping:

const cluesJsx = quizData.clues.slice(0, quizLength).map(clue => {
  // ...
  return (
    <li className="clue-card" key={clue.id}>
      // ...
    </li>
  )
})

That way you don't have to mess around with indexes and stuff

I may not have fully understood what the while was doing so apologies if my suggestion is nonsense 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant