forked from rage/java-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOnlyForAbGroup.js
More file actions
38 lines (33 loc) · 881 Bytes
/
Copy pathOnlyForAbGroup.js
File metadata and controls
38 lines (33 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import React, { Component } from "react"
import withSimpleErrorBoundary from "../../util/withSimpleErrorBoundary"
import AbGroupContext from "../../contexes/AbGroupContext"
class OnlyForAbGroup extends Component {
static contextType = AbGroupContext
state = {
render: false,
}
componentDidMount() {
this.setState({ render: true })
}
render() {
if (!this.state.render) {
return <div>Loading...</div>
}
if (!this.context) {
return (
<div>
Error:. Please use only-for-ab-group only inside of ab-study
components.
</div>
)
}
if (!this.props.group) {
return <div>Error: please provide a group.</div>
}
if (this.props.group === this.context.toString()) {
return this.props.children
}
return <div />
}
}
export default withSimpleErrorBoundary(OnlyForAbGroup)