Guest User

Untitled

a guest
Apr 26th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. export default function whenProps(selector, callback, interval = 50) {
  2.  
  3. const el = document.querySelector(selector);
  4. const reactKey = findReactKey(el);
  5.  
  6. if (el &&
  7. el[reactKey] &&
  8. el[reactKey]._currentElement &&
  9. el[reactKey]._currentElement.props &&
  10. el[reactKey]._currentElement.props.title
  11. ) {
  12.  
  13. return callback(selector);
  14.  
  15. } else {
  16.  
  17. const next = whenProps.bind(null, selector, callback, interval);
  18. return setTimeout(next, interval);
  19.  
  20. }
  21. }
  22.  
  23.  
  24. function findReactKey(elm) {
  25. if (!elm) return false;
  26.  
  27. const objectKeys = Object.keys(elm);
  28. const reactKey = objectKeys.filter(function(key) {
  29. if (key.indexOf('__reactInternalInstance') > -1) return key;
  30. });
  31.  
  32. return reactKey[0];
  33. }
Add Comment
Please, Sign In to add comment