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

**refactor (performance wise): remove unnecessary delay #57

Open
wit03 opened this issue Oct 9, 2024 · 0 comments
Open

**refactor (performance wise): remove unnecessary delay #57

wit03 opened this issue Oct 9, 2024 · 0 comments

Comments

@wit03
Copy link
Member

wit03 commented Oct 9, 2024

Wit's comment:
just remove all setTimeOut to just showing the loading screen

          _:warning: Potential issue_

Fix infinite re-rendering caused by calling load() directly in the component body

Calling load() directly inside the component body leads to setLoading being invoked on every render, causing an infinite loop of re-renders. To fix this, wrap the load() function call inside a useEffect hook with an empty dependency array so it runs only once after the initial render.

Apply this diff to fix the issue:

  const [loading, setLoading] = useState(true)

  const load = () => {
    setTimeout(() => {
      setLoading(false)
    }, 1000)
  }
- load()
+ useEffect(() => {
+   load()
+ }, [])
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

  const load = () => {
    setTimeout(() => {
      setLoading(false)
    }, 1000)
  }
  useEffect(() => {
    load()
  }, [])

Originally posted by @coderabbitai[bot] in #46 (comment)

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