mirror of
https://github.com/yang991178/fluent-reader.git
synced 2025-01-16 18:40:35 +01:00
fix uncontrolled article search
This commit is contained in:
parent
f017bced35
commit
c03e675223
@ -12,7 +12,11 @@ type SearchProps = {
|
||||
dispatch: AppDispatch
|
||||
}
|
||||
|
||||
class ArticleSearch extends React.Component<SearchProps> {
|
||||
type SearchState = {
|
||||
query: string
|
||||
}
|
||||
|
||||
class ArticleSearch extends React.Component<SearchProps, SearchState> {
|
||||
debouncedSearch: (query: string) => void
|
||||
inputRef: React.RefObject<ISearchBox>
|
||||
|
||||
@ -27,10 +31,12 @@ class ArticleSearch extends React.Component<SearchProps> {
|
||||
}
|
||||
}, 750)
|
||||
this.inputRef = React.createRef<ISearchBox>()
|
||||
this.state = { query: props.initQuery }
|
||||
}
|
||||
|
||||
onSearchChange = (_, newValue: string) => {
|
||||
this.debouncedSearch(newValue)
|
||||
this.setState({ query: newValue })
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps: SearchProps) {
|
||||
@ -45,7 +51,7 @@ class ArticleSearch extends React.Component<SearchProps> {
|
||||
componentRef={this.inputRef}
|
||||
className="article-search"
|
||||
placeholder={intl.get("search")}
|
||||
defaultValue={this.props.initQuery}
|
||||
value={this.state.query}
|
||||
onChange={this.onSearchChange} />
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user