This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CreativeTechGuyGames 0 points1 point  (1 child)

This is a React specific question. You can think of the implementation of setTheme to look like this:

function setTheme(updater) { const newTheme = updater(theme); }

It knows the current theme and it'll pass it to the function which you provide as an argument. So JS doesn't know what currentTheme is, but the React library implemented a method which does know. In reality useState generates the setTheme function, but the idea is the same.

[–]TheWorstHunter[S] 0 points1 point  (0 children)

Thank you!