Guest User

Untitled

a guest
Nov 14th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import React, { Component } from 'react';
  2.  
  3. export function createRef() {
  4. const refObject = {
  5. current: null,
  6. };
  7. return refObject;
  8. }
  9.  
  10. export default function D3blackbox(D3render) {
  11. return class Blackbox extends React.Component {
  12. anchor = {
  13. current: null,
  14. };
  15.  
  16. anchorRef = element => (this.anchor.current = element);
  17.  
  18. componentDidMount() {
  19. D3render(this.anchor, this.props, this.state);
  20. }
  21. componentDidUpdate() {
  22. D3render(this.anchor, this.props, this.state);
  23. }
  24.  
  25. render() {
  26. const { x, y } = this.props;
  27. const Component = this.props.component || 'g';
  28.  
  29. return <Component transform={`translate(${x || 0}, ${y || 0})`} ref={this.anchorRef} />;
  30. }
  31. };
  32. }
Add Comment
Please, Sign In to add comment