The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/hooks/useDir.js

27 lines
757 B

import { useEffect, useState } from 'react';
import { Emitter } from '@rocket.chat/emitter';
const ee = new Emitter();
const getDir = () => document.documentElement.getAttribute('dir') || 'ltr';
const config = { attributes: true, childList: false, subtree: false };
const callback = function(mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'dir') {
ee.emit('change', getDir());
}
}
};
const observer = new MutationObserver(callback);
observer.observe(document.documentElement, config);
export const useDir = () => {
const [dir, setDir] = useState(getDir);
useEffect(() => {
ee.on('change', setDir);
return () => ee.off('change', setDir);
}, []);
return dir;
};