|
5 | 5 | * found at http://www.apache.org/licenses/LICENSE-2.0. |
6 | 6 | */ |
7 | 7 |
|
8 | | -import React, { useMemo } from 'react'; |
9 | | -import PropTypes from 'prop-types'; |
10 | | -import { IBodyProps } from '../../types'; |
| 8 | +import React, { HTMLAttributes, useMemo, useState } from 'react'; |
11 | 9 | import { StyledBody } from '../../styled'; |
12 | 10 | import { BodyContext } from '../../utils/useBodyContext'; |
13 | 11 |
|
14 | 12 | /** |
15 | 13 | * @extends HTMLAttributes<HTMLDivElement> |
16 | 14 | */ |
17 | | -export const Body = React.forwardRef<HTMLDivElement, IBodyProps>(({ hasFooter, ...props }, ref) => { |
18 | | - const bodyContextValue = useMemo(() => ({ hasFooter: !!hasFooter }), [hasFooter]); |
| 15 | +export const Body = React.forwardRef<HTMLDivElement, HTMLAttributes<HTMLDivElement>>( |
| 16 | + (props, ref) => { |
| 17 | + const [hasFooter, setHasFooter] = useState(false); |
| 18 | + const bodyContextValue = useMemo( |
| 19 | + () => ({ hasFooter, setHasFooter }), |
| 20 | + [hasFooter, setHasFooter] |
| 21 | + ); |
19 | 22 |
|
20 | | - return ( |
21 | | - <BodyContext.Provider value={bodyContextValue}> |
22 | | - <StyledBody ref={ref} {...props} /> |
23 | | - </BodyContext.Provider> |
24 | | - ); |
25 | | -}); |
| 23 | + return ( |
| 24 | + <BodyContext.Provider value={bodyContextValue}> |
| 25 | + <StyledBody ref={ref} {...props} /> |
| 26 | + </BodyContext.Provider> |
| 27 | + ); |
| 28 | + } |
| 29 | +); |
26 | 30 |
|
27 | 31 | Body.displayName = 'Body'; |
28 | | - |
29 | | -Body.propTypes = { |
30 | | - hasFooter: PropTypes.bool |
31 | | -}; |
0 commit comments