-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathMockProvider.tsx
40 lines (35 loc) · 979 Bytes
/
MockProvider.tsx
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
39
40
import React, { Component, ReactNode } from 'react';
import PropTypes from 'prop-types';
import { ParallaxContext } from '../../src/context/ParallaxContext';
import { ParallaxController } from 'parallax-controller';
export class MockProvider extends Component<{
children: ReactNode;
controllerMock: ParallaxController;
}> {
static propTypes = {
children: PropTypes.node.isRequired,
controllerMock: PropTypes.object.isRequired,
};
controller: ParallaxController;
constructor(props: {
children: ReactNode;
controllerMock: ParallaxController;
}) {
super(props);
this.controller = props.controllerMock;
}
componentWillUnmount() {
if (!this.controller) return;
this.controller.destroy();
// @ts-ignore
this.controller = undefined;
}
render() {
const { children } = this.props;
return (
<ParallaxContext.Provider value={this.controller}>
{children}
</ParallaxContext.Provider>
);
}
}