-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: task6 (Redux) #5
base: task5
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,31 @@ | ||
import React from 'react'; | ||
import React, { useEffect, useState } from 'react'; | ||
|
||
import styles from './search.module.scss'; | ||
import useAppDispatch from '../../Hooks/useAppDispatch'; | ||
import { searchMoviesByTitle } from '../../Containers/MovieList/movieListSlice'; | ||
|
||
const Search: React.FunctionComponent = () => { | ||
const [searchText, setSearchText] = useState(''); | ||
const dispatch = useAppDispatch(); | ||
|
||
const handleOnChange = e => setSearchText(e.target.value); | ||
|
||
useEffect(() => { | ||
if (searchText?.length > 2) { | ||
dispatch(searchMoviesByTitle(searchText)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. в учебке не так важно, но в проде лучше использовать debounce если поиск происходит на сервере, чтобы на каждый введенный символ (а пользователи обычно вводят быстро) не происходил ненужный запрос |
||
} | ||
}, [searchText, dispatch]); | ||
return ( | ||
<> | ||
<h2 className={styles.searchText}>find your movie</h2> | ||
<div className={styles.searchInputWrapper}> | ||
<input className={styles.searchInput} type="search" placeholder="What do you want to watch?" /> | ||
<input | ||
className={styles.searchInput} | ||
type="search" | ||
value={searchText} | ||
onChange={handleOnChange} | ||
placeholder="What do you want to watch?" | ||
/> | ||
<button className={styles.searchButton} type="button"> | ||
search | ||
</button> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,6 @@ | |
align-items: center; | ||
margin: auto; | ||
width: 100%; | ||
height: 100%; | ||
height: 100vh; | ||
background: #424242; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
если этот набор параметров не будет меняться, то можно его не держать в реактовом компоненте а вынести например за пределы (между 5 и 7 строкой) и будет просто const
NAV_ITMES = ['all', 'documentary', 'comedy', 'horror', 'crime']
. тогда и useMemo не нужен и в зависимостях эффекта можно не держатьThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
еще для простых конструкций можно
JSON.stringify(navItems)
вот тут подробно написано facebook/react#14476 (comment)