# Problem with React Leaderboard \[SOLVED\]

**URL:** <https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187>\
**Category:** I Built This\
**Created:** [August 11, 2017, 6:01pm UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187 "2017-08-11T18:01:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukaszsobek](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukaszsobek/32/64174_2.png) [@lukaszsobek](https://forum.freecodecamp.org/u/lukaszsobek)\
**Post date:** [August 11, 2017, 6:01pm UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187/1 "2017-08-11T18:01:45Z")

</div>

Having just finished a working version of the leaderboard I ran into a problem.

Request:  
Please point me in the right direction as to why the problem is occurring. Also any remarks as to code clarity and quality are appreciated.

Problem:  
switching between “alltime” and “30day” causes the display to flicker based on how many times you switch between the two options.

Codepen:

> **[FreeCodeCamp Leaderboard](https://codepen.io/lukaszsobek/pen/rzzOby)**
>
> ...

---

<div class="post-metadata">

**Author:** ![lukaszsobek](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukaszsobek/32/64174_2.png) [@lukaszsobek](https://forum.freecodecamp.org/u/lukaszsobek)\
**Post date:** [August 13, 2017, 2:30pm UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187/2 "2017-08-13T14:30:50Z")

</div>

Problem fixed - removed reference to the update function from the render body itself and moved it into:

- a clickhandler for change and
- componentDidmount for initial display

works nicely now.

---

<div class="post-metadata">

**Author:** ![jenovs](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jenovs/32/60963_2.png) [@jenovs](https://forum.freecodecamp.org/u/jenovs)\
**Post date:** [August 15, 2017, 7:13am UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187/3 "2017-08-15T07:13:10Z")

</div>

Quick code review.

* * *

CSS

Stick to one type of class names (`dataitem`, `recentLink`). I use `my-cool-class`. And btw, writingeverythinginoneword should be avoided (`dataitem` 😒)  
And I think the font you’re trying to use is called **Verdana**

* * *

React

If you make both requests when app loads and save both to state you can switch instantly between both lists and no further network requests required (you could add functionality to periodically fetch in the background, say, every hour). Also FCC has limit on their API so this is the best approach here.

Accessing elements with `document.getElementBy...` is not a very “react way”.

I made some refactorings in your code (I’m not saying it’s the best way to do it, just one of the ways):

> **[Leaderboard Re-factor](https://codepen.io/jenovs/pen/oeGROg?editors=0010)**
>
> ...

Also there is ‘Tidy JS’ option in CodePen to help format your code.

---

<div class="post-metadata">

**Author:** ![lukaszsobek](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lukaszsobek/32/64174_2.png) [@lukaszsobek](https://forum.freecodecamp.org/u/lukaszsobek)\
**Post date:** [August 17, 2017, 9:38am UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187/4 "2017-08-17T09:38:02Z")

</div>

Thank you 🙂 Will read through the pen to take a look at all the things you mentioned here. Great job!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 2:29pm UTC](https://forum.freecodecamp.org/t/problem-with-react-leaderboard-solved/141187/5 "2021-06-01T14:29:15Z")

</div>

Closed on June 1, 2021, 2:29pm UTC


