Skip to content

Commit 582bc46

Browse files
authored
fix(typography): move useContext above early return in Heading (#50)
1 parent 167031e commit 582bc46

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

.changeset/fix-heading-hook.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@tiny-design/react': patch
3+
---
4+
5+
Fix conditional hook call in Heading component

packages/react/src/typography/heading.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { HeadingProps } from './types';
77
const Heading = React.forwardRef<HTMLHeadingElement, HeadingProps>(
88
(props, ref) => {
99
const { level = 1, prefixCls: customisedCls, className, children, ...otherProps } = props;
10+
const configContext = useContext(ConfigContext);
11+
const prefixCls = getPrefixCls('typography', configContext.prefixCls, customisedCls);
1012

1113
if (level < 1 || level > 6) {
1214
console.warn('The heading level parameter is invalid.');
1315
return null;
1416
}
15-
16-
const configContext = useContext(ConfigContext);
17-
const prefixCls = getPrefixCls('typography', configContext.prefixCls, customisedCls);
1817
const cls = classNames(prefixCls, className);
1918

2019
return React.createElement(

0 commit comments

Comments
 (0)