cordis/archive/external-stores.ts
2022-10-23 14:11:26 -07:00

33 lines
915 B
TypeScript

import * as electronRemote from '@electron/remote';
const electronConsole = electronRemote.getGlobal('console') as Console;
import Logger from '../../../../logger/logger';
const LOG = Logger.create(__filename, electronConsole);
import { useEffect, useSyncExternalStore } from 'react';
import { atom, useSetRecoilState } from 'recoil';
export const exampleState = atom<number>({
key: 'exampleState',
default: 4,
});
export function useExampleStateSubscription() {
LOG.debug('using');
const setExample = useSetRecoilState(exampleState);
const value = useSyncExternalStore(
() => {
LOG.debug('subscribing');
return () => {
LOG.debug('unsubscribing')
};
},
() => {
LOG.debug('returning');
return 6;
},
);
useEffect(() => {
setExample(value);
}, [setExample, value])
}