Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default function whenProps(selector, callback, interval = 50) {
- const el = document.querySelector(selector);
- const reactKey = findReactKey(el);
- if (el &&
- el[reactKey] &&
- el[reactKey]._currentElement &&
- el[reactKey]._currentElement.props &&
- el[reactKey]._currentElement.props.title
- ) {
- return callback(selector);
- } else {
- const next = whenProps.bind(null, selector, callback, interval);
- return setTimeout(next, interval);
- }
- }
- function findReactKey(elm) {
- if (!elm) return false;
- const objectKeys = Object.keys(elm);
- const reactKey = objectKeys.filter(function(key) {
- if (key.indexOf('__reactInternalInstance') > -1) return key;
- });
- return reactKey[0];
- }
Add Comment
Please, Sign In to add comment