Converted Class Component to Function Component, Solved #24783 (#24812)

* Converted Class Component to Function Component, Solved #24783

* Added useCallback

* Removed useState

* Wrapped TeamFilterCheckbox component with React.memo

* Added React.nemo in export line

* Tried to fix issue

* Deleted package.json and package-lock.json (Extra)

* Minor Changes

* Added Copyright Lines

* Fixed check-lint errors

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Saket Kaswa
2023-10-24 21:23:15 +05:30
коммит произвёл GitHub
родитель 4a0cf786be
Коммит a64bc3af7a

Просмотреть файл

@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information. // See LICENSE.txt for license information.
import React from 'react'; import React, {useCallback} from 'react';
type Props = { type Props = {
id: string; id: string;
@@ -11,19 +11,16 @@ type Props = {
updateOption: (checked: boolean, name: string) => void; updateOption: (checked: boolean, name: string) => void;
}; };
class TeamFilterCheckbox extends React.PureComponent<Props> { const TeamFilterCheckbox = ({
toggleOption = () => {
const {checked, id, updateOption} = this.props;
updateOption(!checked, id);
};
render() {
const {
checked,
id, id,
label,
name, name,
} = this.props; checked,
label,
updateOption,
}: Props) => {
const toggleOption = useCallback(() => {
updateOption(!checked, id);
}, [checked, id, updateOption]);
return ( return (
<div className='TeamFilterDropdown_checkbox'> <div className='TeamFilterDropdown_checkbox'>
@@ -33,14 +30,13 @@ class TeamFilterCheckbox extends React.PureComponent<Props> {
id={id} id={id}
name={name} name={name}
checked={checked} checked={checked}
onChange={this.toggleOption} onChange={toggleOption}
/> />
{label} {label}
</label> </label>
</div> </div>
); );
} };
}
export default TeamFilterCheckbox; export default React.memo(TeamFilterCheckbox);