Skip to content

Commit

Permalink
fix: Alternative without useEffect for prev generated token
Browse files Browse the repository at this point in the history
  • Loading branch information
calvin-codecov committed Dec 12, 2024
1 parent 9cf61eb commit 3e1b759
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect, useRef, useState } from 'react'
import { useRef, useState } from 'react'
import { useParams } from 'react-router-dom'

import { useOrgUploadToken } from 'services/orgUploadToken'
Expand Down Expand Up @@ -53,13 +53,11 @@ function GitHubActions() {
(isUsingGlobalToken && !!orgUploadToken) ||
(!isUsingGlobalToken && !!repoUploadToken)

useEffect(() => {
// Only set this on initial render
if (previouslyGeneratedOrgToken.current === undefined) {
previouslyGeneratedOrgToken.current = orgUploadToken
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
// If orgUploadToken does not exist on initial render, set it to null and we
// do not touch it again on rerenders
if (previouslyGeneratedOrgToken.current === undefined) {
previouslyGeneratedOrgToken.current = orgUploadToken ?? null
}

const [framework, setFramework] = useState<Framework>('Jest')

Expand Down

0 comments on commit 3e1b759

Please sign in to comment.