All files / packages/react-tao/src DataHandler.js

25% Statements 3/12
100% Branches 0/0
25% Functions 1/4
25% Lines 3/12
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            8x     12x 6x                                                      
import React, { Component } from 'react';
 
import { Context } from './Provider';
import createContextHandler from './createContextHandler';
 
export default class DataHandler extends Component {
  static contextType = Context;
 
  constructor(props) {
    super(props);
    this.ChildContext = createContextHandler(
      props,
      props.handler,
      props.default
    );
  }
 
  componentDidMount() {
    const { name } = this.props;
    const { setDataContext } = this.context;
    setDataContext(name, this.ChildContext);
  }
 
  componentWillUnmount() {
    const { name } = this.props;
    const { removeDataContext } = this.context;
    removeDataContext(name);
  }
 
  render() {
    const { children } = this.props;
    const Provider = this.ChildContext.Provider;
    // use React.Children here to inject the context somehow?
    // https://reactjs.org/docs/react-api.html#reactchildren
    return <Provider>{children}</Provider>;
  }
}