Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const LoadableComponent = (props, ref) => {
init()
const context = React.useContext(LoadableContext)
const state = useSubscription(subscription)
React.useImperativeHandle(ref, () => ({
retry: subscription.retry,
}))
if (context && Array.isArray(opts.modules)) {
opts.modules.forEach(moduleName => {
context(moduleName)
})
}
if (state.loading || state.error) {
return React.createElement(opts.loading, {
isLoading: state.loading,
pastDelay: state.pastDelay,
timedOut: state.timedOut,
function useRtl() {
return useSubscription( RtlSubscription );
}
export function useLocation() {
const subscription = useMemo(
() => ({
getCurrentValue: () => globalHistory.location,
subscribe: callback => globalHistory.listen(callback),
}),
[]
);
return useSubscription(subscription);
}
function useCount(store) {
return useSubscription(React.useMemo(() => ({
getCurrentValue: () => store.count,
subscribe: (cb) => mobx.autorun(cb),
}), [store]));
}
export default function useColorScheme(): ?ColorSchemeName {
const subscription = useMemo(
() => ({
getCurrentValue: () => Appearance.getColorScheme(),
subscribe: callback => {
Appearance.addChangeListener(callback);
return () => Appearance.removeChangeListener(callback);
},
}),
[],
);
return useSubscription(subscription);
}
const Counter = React.memo(() => {
const count = useSubscription(React.useMemo(() => ({
getCurrentValue: () => store.getState().count,
subscribe: (callback) => store.subscribe(callback),
}), []));
syncBlock();
return <div>{count}</div>;
}, shallowEqual);
export default function useSubscriptionImmediateSuspense(
subscription,
cleanupDelay = 30000
) {
if (!subscription.getCurrentValue()) {
throw new Promise(resolve => {
const unsubscribe = subscription.subscribe(resolve);
setTimeout(unsubscribe, cleanupDelay);
});
}
return useSubscription(subscription);
}