Skip to content

Commit ae7fcb1

Browse files
committed
Modified use of useEffect hook
1 parent 7952e35 commit ae7fcb1

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

.eslintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ env:
88
root: true
99
plugins:
1010
- react
11+
- react-hooks
1112
rules:
1213
arrow-spacing: 'error'
1314
no-const-assign: 'error'
@@ -16,3 +17,5 @@ rules:
1617
prefer-template: 'error'
1718
prefer-destructuring: ['error', { 'object': true, 'array': false }]
1819
object-curly-spacing: [2, 'always']
20+
react-hooks/rules-of-hooks: 'error'
21+
react-hooks/exhaustive-deps: 'warn'

src/modules/TitleSearch.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import React, { useState, useEffect, useCallback } from 'react'
2-
import { debounce } from 'lodash'
1+
import React, { useState, useEffect } from 'react'
32
import userStory from '../services/user_story'
43
import { strip } from '../utils/filterText'
54
import { EOS_ARROW_FORWARD, EOS_THUMB_UP } from 'eos-icons-react'
@@ -9,20 +8,14 @@ const Search = (props) => {
98

109
const [searchResults, setSearchResults] = useState([])
1110

12-
const handleTitleChange = useCallback(
13-
debounce(async (title) => {
11+
useEffect(() => {
12+
if (!title) return
13+
14+
setTimeout(async () => {
1415
const response = await userStory.getStoriesByTitle(title)
1516
setSearchResults(response.data.data.userStories)
16-
}, 600),
17-
[]
18-
)
19-
20-
useEffect(() => {
21-
if (!title) {
22-
return
23-
}
24-
handleTitleChange(title)
25-
}, [title, handleTitleChange])
17+
}, 600)
18+
}, [title])
2619

2720
if (!title) {
2821
return ''

0 commit comments

Comments
 (0)