Skip to content

Commit c14d0ac

Browse files
author
himaniraghav3
committed
Change useEffect to useMemo
1 parent 238f238 commit c14d0ac

File tree

1 file changed

+9
-12
lines changed
  • src/apps/copilots/src/pages/copilot-request-form

1 file changed

+9
-12
lines changed

src/apps/copilots/src/pages/copilot-request-form/index.tsx

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { FC, useContext, useEffect, useState } from 'react'
1+
import { FC, useContext, useMemo, useState } from 'react'
22
import { bind, isEmpty } from 'lodash'
33
import { toast } from 'react-toastify'
44
import classNames from 'classnames'
@@ -21,21 +21,18 @@ const CopilotRequestForm: FC<{}> = () => {
2121
const [isFormChanged, setIsFormChanged] = useState(false)
2222
const [formErrors, setFormErrors] = useState<any>({})
2323
const [searchTerm, setSearchTerm] = useState<string>('')
24-
const [projects, setProjects] = useState<InputSelectOption[]>([])
2524
const { data: projectsData }: { data?: Project[] } = useFetchProjects(searchTerm)
2625
const [existingCopilot, setExistingCopilot] = useState<string>('')
2726
const [paymentType, setPaymentType] = useState<string>('')
2827

29-
useEffect(() => {
30-
if (projectsData) {
31-
setProjects(
32-
projectsData.map(project => ({
33-
label: project.name,
34-
value: project.id,
35-
})),
36-
)
37-
}
38-
}, [projectsData])
28+
const projects = useMemo(
29+
() => (
30+
projectsData
31+
? projectsData.map(project => ({ label: project.name, value: project.id }))
32+
: []
33+
),
34+
[projectsData],
35+
)
3936

4037
const projectTypes = ProjectTypes ? ProjectTypes.map(project => ({
4138
label: project,

0 commit comments

Comments
 (0)