Files
twenty/front/src/modules/debug/components/RecoilDebugObserver.tsx
T
gitstart-twenty 00a3c8ca2b Change to using arrow functions (#1603)
* Change to using arrow functions

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>

* Add lint rule

---------

Co-authored-by: v1b3m <vibenjamin6@gmail.com>
Co-authored-by: Matheus <matheus_benini@hotmail.com>
Co-authored-by: Charles Bochet <charles@twenty.com>
2023-09-15 18:41:10 -07:00

46 lines
1.0 KiB
TypeScript

import { useEffect } from 'react';
import { useRecoilSnapshot, useRecoilValue } from 'recoil';
import { isDebugModeState } from '@/client-config/states/isDebugModeState';
const formatTitle = (stateName: string) => {
const headerCss = [
'color: gray; font-weight: lighter',
'color: black; font-weight: bold;',
];
const parts = ['%c recoil', `%c${stateName}`];
return [parts.join(' '), ...headerCss];
};
export const RecoilDebugObserverEffect = () => {
const snapshot = useRecoilSnapshot();
const isDebugMode = useRecoilValue(isDebugModeState);
useEffect(() => {
if (!isDebugMode) {
return;
}
for (const node of Array.from(
snapshot.getNodes_UNSTABLE({ isModified: true }),
)) {
const loadable = snapshot.getLoadable(node);
const titleArgs = formatTitle(node.key);
console.groupCollapsed(...titleArgs);
console.log('STATE', loadable.state);
console.log('CONTENTS', loadable.contents);
console.groupEnd();
}
}, [isDebugMode, snapshot]);
return null;
};