Currently i am exporting only one funtin like this and it works great
JavaScript
x
17
17
1
import React from "react";
2
import SocialLogin from "from somewwhere";
3
4
class GoogleButton extends React.Component {
5
render() {
6
const { fontClass, triggerLogin, props } = this.props;
7
return (
8
9
<div className="">
10
Google
11
</div>
12
13
);
14
}
15
}
16
export default SocialLogin(GoogleButton);
17
But when I try to export multiple functions, it doesn’t work.
JavaScript
1
35
35
1
import React from "react";
2
import SocialLogin from "from somewhere";
3
4
class GoogleButton extends React.Component {
5
render() {
6
const { fontClass, triggerLogin, props } = this.props;
7
return (
8
9
<div className="">
10
Google
11
</div>
12
13
);
14
}
15
}
16
17
18
class FacebookButton extends React.Component {
19
render() {
20
const { fontClass, triggerLogin, props } = this.props;
21
return (
22
23
<div className="">
24
Facebook
25
</div>
26
27
);
28
}
29
}
30
31
export {
32
SocialLogin(GoogleButton),
33
SocialLogin(FacebookButton);
34
}
35
Can anyone tell me why it doesnt work? It works when i do like this
JavaScript
1
5
1
export {
2
SomeFunc,
3
AnotherFun,
4
}
5
But what’s wrong with it if i put it inside a functin? Can anyone tell me how can i do it?
Advertisement
Answer
You cam simply do this.
JavaScript
1
30
30
1
import React from "react";
2
import SocialLogin from "from somewhere";
3
4
export class GoogleButton extends React.Component {
5
render() {
6
const { fontClass, triggerLogin, props } = this.props;
7
return (
8
9
<div className="">
10
Google
11
</div>
12
13
);
14
}
15
}
16
17
18
export class FacebookButton extends React.Component {
19
render() {
20
const { fontClass, triggerLogin, props } = this.props;
21
return (
22
23
<div className="">
24
Facebook
25
</div>
26
27
);
28
}
29
}
30
Or you can do this.
JavaScript
1
7
1
Existing components .
2
3
export default {
4
SocialLoginGoogle: SocialLogin(GoogleButton),
5
SocialLoginFacebook: SocialLogin(FacebookButton)
6
}
7
The below one works as it is considering object’s key
and value
has the same name. Hence, shorthand.
JavaScript
1
5
1
export {
2
SomeFunc,
3
AnotherFun,
4
}
5