Skip to content

Commit

Permalink
Refactor to Typescript and Remove defaultProps and instead use React …
Browse files Browse the repository at this point in the history
…default parameters
  • Loading branch information
meziyum committed Jul 7, 2024
1 parent 5f6d914 commit 2d6f83a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/js/Components/Search.jsx → src/js/Components/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {
}
from '@fortawesome/free-solid-svg-icons';

interface SearchPropType{
updateSearch: Function,
value?: string,
label: string,
}

/**
A component for searching.
@component
Expand All @@ -17,17 +23,17 @@ A component for searching.
@param {string} props.label - Label for the search
@return {JSX.Element} A form element containing an input for searching novels.
*/
export default function Search({updateSearch, value, label}) {
export default function Search({updateSearch, value='', label='Novel'}: SearchPropType): JSX.Element {
const [search, updateSearchState] =React.useState(value);

const handleInput = (event) => {
const handleInput = (event: React.ChangeEvent<HTMLInputElement>) => {
updateSearchState(event.target.value);
if (event.target.value === '') {
updateSearch(event, event.target.value);
}
};

const handleSubmit = (event) => {
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
updateSearch(event, search);
};
Expand All @@ -52,9 +58,4 @@ Search.propTypes = {
value: propTypes.string,
updateSearch: propTypes.func.isRequired,
label: propTypes.string.isRequired,
};

Search.defaultProps ={
value: '',
label: 'Novel',
};
};

0 comments on commit 2d6f83a

Please sign in to comment.