File tree Expand file tree Collapse file tree 1 file changed +16
-29
lines changed Expand file tree Collapse file tree 1 file changed +16
-29
lines changed Original file line number Diff line number Diff line change 1
1
import PropTypes from 'prop-types' ;
2
- import React from 'react' ;
2
+ import React , { useEffect , useRef } from 'react' ;
3
3
4
- class NativeCheckbox extends React . PureComponent {
5
- static propTypes = {
6
- indeterminate : PropTypes . bool ,
7
- } ;
4
+ const propTypes = {
5
+ indeterminate : PropTypes . bool ,
6
+ } ;
7
+ const defaultProps = {
8
+ indeterminate : false ,
9
+ } ;
8
10
9
- static defaultProps = {
10
- indeterminate : false ,
11
- } ;
11
+ function NativeCheckbox ( { indeterminate, ...otherProps } ) {
12
+ const checkbox = useRef ( null ) ;
12
13
13
- componentDidMount ( ) {
14
- this . updateDeterminateProperty ( ) ;
15
- }
14
+ useEffect ( ( ) => {
15
+ checkbox . current . indeterminate = indeterminate ;
16
+ } ) ;
16
17
17
- componentDidUpdate ( ) {
18
- this . updateDeterminateProperty ( ) ;
19
- }
20
-
21
- updateDeterminateProperty ( ) {
22
- const { indeterminate } = this . props ;
23
-
24
- this . checkbox . indeterminate = indeterminate ;
25
- }
26
-
27
- render ( ) {
28
- const props = { ...this . props } ;
29
-
30
- // Remove property that does not exist in HTML
31
- delete props . indeterminate ;
32
-
33
- return < input { ...props } ref = { ( c ) => { this . checkbox = c ; } } type = "checkbox" /> ;
34
- }
18
+ return < input { ...otherProps } ref = { checkbox } type = "checkbox" /> ;
35
19
}
36
20
21
+ NativeCheckbox . propTypes = propTypes ;
22
+ NativeCheckbox . defaultProps = defaultProps ;
23
+
37
24
export default NativeCheckbox ;
You can’t perform that action at this time.
0 commit comments