Skip to content

Commit adbbfff

Browse files
Walkeryrdanilowoz
authored andcommitted
Removed state from ContentLoader component (#45)
* Removed state from ContentLoader component * Converting ContentLoader from class to functional component
1 parent 5672a93 commit adbbfff

File tree

1 file changed

+26
-58
lines changed

1 file changed

+26
-58
lines changed

src/index.js

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,40 @@ export type Props = {
2424
className: string,
2525
}
2626

27-
type State = {
28-
style: { [key: string]: any },
29-
type: string,
30-
speed: number,
31-
width: number,
32-
height: number,
33-
primaryColor: string,
34-
secondaryColor: string,
35-
preserveAspectRatio: string,
36-
className: string,
37-
}
38-
39-
class ContentLoader extends React.Component<Props, State> {
40-
static defaultProps = {
41-
type: 'facebook',
42-
speed: 2,
43-
width: 400,
44-
height: 130,
45-
primaryColor: '#f0f0f0',
46-
secondaryColor: '#e0e0e0',
47-
preserveAspectRatio: 'xMidYMid meet',
48-
className: '',
49-
}
50-
51-
constructor(props: Props) {
52-
super(props)
53-
54-
this.state = {
55-
style: props.style,
56-
type: props.type,
57-
speed: props.speed,
58-
width: props.width,
59-
height: props.height,
60-
primaryColor: props.primaryColor,
61-
secondaryColor: props.secondaryColor,
62-
preserveAspectRatio: props.preserveAspectRatio,
63-
className: props.className,
64-
}
27+
const ContentLoader = (props: Props) => {
28+
if (props.children) {
29+
return <Wrap {...props}>{props.children}</Wrap>
6530
}
6631

67-
render() {
68-
if (this.props.children) {
69-
return <Wrap {...this.state}>{this.props.children}</Wrap>
70-
}
32+
switch (props.type.toLowerCase()) {
33+
case 'instagram':
34+
return <InstagramStyle {...props} />
7135

72-
if (!this.props.children) {
73-
switch (this.state.type.toLowerCase()) {
74-
case 'instagram':
75-
return <InstagramStyle {...this.state} />
36+
case 'code':
37+
return <CodeStyle {...props} />
7638

77-
case 'code':
78-
return <CodeStyle {...this.state} />
39+
case 'list':
40+
return <ListStyle {...props} />
7941

80-
case 'list':
81-
return <ListStyle {...this.state} />
42+
case 'bullet-list':
43+
return <BulletListStyle {...props} />
8244

83-
case 'bullet-list':
84-
return <BulletListStyle {...this.state} />
85-
86-
default:
87-
case 'facebook':
88-
return <FacebookStyle {...this.state} />
89-
}
90-
}
45+
default:
46+
case 'facebook':
47+
return <FacebookStyle {...props} />
9148
}
9249
}
9350

51+
ContentLoader.defaultProps = {
52+
type: 'facebook',
53+
speed: 2,
54+
width: 400,
55+
height: 130,
56+
primaryColor: '#f0f0f0',
57+
secondaryColor: '#e0e0e0',
58+
preserveAspectRatio: 'xMidYMid meet',
59+
className: '',
60+
};
61+
9462
export default ContentLoader
9563
export { Rect, Circle }

0 commit comments

Comments
 (0)