Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit 2d262d4

Browse files
committed
refactor: refactor components to functions
1 parent b61d731 commit 2d262d4

File tree

7 files changed

+30
-33
lines changed

7 files changed

+30
-33
lines changed

.size-snapshot.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
22
"lib/index.esm.js": {
3-
"bundled": 5035,
4-
"minified": 2602,
5-
"gzipped": 945,
3+
"bundled": 4740,
4+
"minified": 2528,
5+
"gzipped": 923,
66
"treeshaked": {
77
"rollup": {
8-
"code": 1185,
8+
"code": 1146,
99
"import_statements": 195
1010
},
1111
"webpack": {
12-
"code": 3075
12+
"code": 3036
1313
}
1414
}
1515
}

src/components/List/List.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ interface IListProps {
1818
/**
1919
* Renders content from specified callback function from either `render` or `children` on each element of `items`.
2020
*/
21-
const List = (props: IListProps): TOutput => {
22-
const { items, children, render } = props;
23-
const renderProp = getRenderProp(children, render);
21+
function List(props: IListProps): TOutput {
22+
const renderProp = getRenderProp(props.children, props.render);
2423

2524
if (!!renderProp && isFunction<TMap>(renderProp)) {
26-
return <React.Fragment>{items.map(renderProp)}</React.Fragment>;
25+
return <React.Fragment>{props.items.map(renderProp)}</React.Fragment>;
2726
}
2827

2928
return null;
30-
};
29+
}
3130

3231
List.propTypes = {
3332
children: PropTypes.func,

src/components/Show/Show.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ interface IShowProps extends IRenderProps {
1111
/**
1212
* Renders content if `when` equals true.
1313
*/
14-
const Show = (props: IShowProps): TOutput => {
15-
const { when, children, render } = props;
16-
return when ? getChildrenOrRender(children, render) : null;
17-
};
14+
function Show(props: IShowProps): TOutput {
15+
return props.when ? getChildrenOrRender(props.children, props.render) : null;
16+
}
1817

1918
Show.propTypes = {
2019
when: PropTypes.bool.isRequired,

src/components/ShowIfElse/ShowIfElse.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@ interface IShowIfElse {
1818
/**
1919
* Renders content from if when condition equals true, else renders content from else.
2020
*/
21-
const ShowIfElse = (props: IShowIfElse): TOutput => (
22-
<Switch value={true}>
23-
<Switch.Case value={props.condition} render={props.if} />
24-
<Switch.Default render={props.else} />
25-
</Switch>
26-
);
21+
function ShowIfElse(props: IShowIfElse): TOutput {
22+
return (
23+
<Switch value={true}>
24+
<Switch.Case value={props.condition} render={props.if} />
25+
<Switch.Default render={props.else} />
26+
</Switch>
27+
);
28+
}
2729

2830
ShowIfElse.propTypes = {
2931
condition: PropTypes.bool.isRequired,

src/components/Switch/Switch.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ const getSwitchCaseValue = (element: any) => element.props.value;
1818
/**
1919
* Renders content from first `Switch.Case` that matches `value`, else `Switch.Default` if it exists.
2020
*/
21-
const Switch = (props: ISwitchProps): TOutput => {
22-
const { children, value } = props;
23-
const switchValue = value;
21+
function Switch(props: ISwitchProps): TOutput {
22+
const switchValue = props.value;
2423
let match = false;
2524
let child: any;
2625

27-
React.Children.forEach(children, (element: any) => {
26+
React.Children.forEach(props.children, (element: any) => {
2827
if (match === false && React.isValidElement(element)) {
2928
const caseValue = getSwitchCaseValue(element);
3029
child = element;
@@ -39,7 +38,7 @@ const Switch = (props: ISwitchProps): TOutput => {
3938

4039
// Return case if its a match.
4140
return match ? React.cloneElement(child) : null;
42-
};
41+
}
4342

4443
Switch.Case = SwitchCase;
4544

src/components/Switch/SwitchCase.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ export interface ISwitchCaseProps extends IRenderProps {
1111
/**
1212
* Helper component that is accessed from `Switch` component.
1313
*/
14-
const SwitchCase = (props: ISwitchCaseProps): TOutput => {
15-
const { children, render } = props;
16-
return getChildrenOrRender(children, render);
17-
};
14+
function SwitchCase(props: ISwitchCaseProps): TOutput {
15+
return getChildrenOrRender(props.children, props.render);
16+
}
1817

1918
SwitchCase.propTypes = {
2019
value: PropTypes.any.isRequired,

src/components/Switch/SwitchDefault.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ import { getChildrenOrRender } from '../../utils/';
44
/**
55
* Helper component that is accessed from `Switch` component.
66
*/
7-
const SwitchDefault = (props: IRenderProps): TOutput => {
8-
const { children, render } = props;
9-
return getChildrenOrRender(children, render);
10-
};
7+
function SwitchDefault(props: IRenderProps): TOutput {
8+
return getChildrenOrRender(props.children, props.render);
9+
}
1110

1211
SwitchDefault.propTypes = renderPropsPropTypes;
1312

0 commit comments

Comments
 (0)