mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
|
// @flow
|
||
|
import * as React from 'react';
|
||
|
import createContext, { type Context } from '@hypnosphi/create-react-context';
|
||
|
export const ManagerReferenceNodeContext: Context<?HTMLElement> = createContext();
|
||
|
export const ManagerReferenceNodeSetterContext: Context<
|
||
|
void | ((?HTMLElement) => void)
|
||
|
> = createContext();
|
||
|
|
||
|
export type ManagerProps = {
|
||
|
children: React.Node,
|
||
|
};
|
||
|
|
||
|
export default class Manager extends React.Component<ManagerProps> {
|
||
|
referenceNode: ?HTMLElement;
|
||
|
|
||
|
setReferenceNode = (newReferenceNode: ?HTMLElement) => {
|
||
|
if (newReferenceNode && this.referenceNode !== newReferenceNode) {
|
||
|
this.referenceNode = newReferenceNode;
|
||
|
this.forceUpdate();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
componentWillUnmount() {
|
||
|
this.referenceNode = null;
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
return (
|
||
|
<ManagerReferenceNodeContext.Provider value={this.referenceNode}>
|
||
|
<ManagerReferenceNodeSetterContext.Provider
|
||
|
value={this.setReferenceNode}
|
||
|
>
|
||
|
{this.props.children}
|
||
|
</ManagerReferenceNodeSetterContext.Provider>
|
||
|
</ManagerReferenceNodeContext.Provider>
|
||
|
);
|
||
|
}
|
||
|
}
|