Home / File/ UseSyncExternalStore.js — react Source File

UseSyncExternalStore.js — react Source File

Architecture documentation for UseSyncExternalStore.js, a javascript file in the react codebase. 1 imports, 1 dependents.

File javascript BabelCompiler Validation 1 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  6f8c8341_f698_aa09_38ec_769387a9cfef["UseSyncExternalStore.js"]
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  6f8c8341_f698_aa09_38ec_769387a9cfef --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  ee521c92_6aea_ed48_b3b2_59ca21d468e3["InspectableElements.js"]
  ee521c92_6aea_ed48_b3b2_59ca21d468e3 --> 6f8c8341_f698_aa09_38ec_769387a9cfef
  style 6f8c8341_f698_aa09_38ec_769387a9cfef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 * @flow
 */

import * as React from 'react';

const {useState, useEffect, useSyncExternalStore} = React;

// Create a simple external store for demonstratio
function createStore<T>(initialValue: T): {
  subscribe: (cb: () => void) => () => any,
  getSnapshot: () => T,
  setValue: (newValue: T) => void,
} {
  let value = initialValue;
  const subscribers = new Set<() => void>();

  return {
    subscribe(callback) {
      subscribers.add(callback);
      return () => subscribers.delete(callback);
    },
    getSnapshot() {
      return value;
    },
    setValue(newValue) {
      value = newValue;
      subscribers.forEach(callback => callback());
    },
  };
}

const counterStore = createStore(0);
const themeStore = createStore('light');

export default function UseSyncExternalStore(): React.Node {
  return (
    <>
      <h2>useSyncExternalStore()</h2>
      <SingleHookCase />
      <HookTreeCase />
      <MultipleStoresCase />
    </>
  );
}

function SingleHookCase(): React.Node {
  const count = useSyncExternalStore(
    counterStore.subscribe,
    counterStore.getSnapshot,
  );

  return (
    <div>
      <h3>Single hook case</h3>
// ... (74 more lines)

Domain

Subdomains

Functions

Dependencies

  • react

Frequently Asked Questions

What does UseSyncExternalStore.js do?
UseSyncExternalStore.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in UseSyncExternalStore.js?
UseSyncExternalStore.js defines 1 function(s): subscribers.
What does UseSyncExternalStore.js depend on?
UseSyncExternalStore.js imports 1 module(s): react.
What files import UseSyncExternalStore.js?
UseSyncExternalStore.js is imported by 1 file(s): InspectableElements.js.
Where is UseSyncExternalStore.js in the architecture?
UseSyncExternalStore.js is located at packages/react-devtools-shell/src/app/InspectableElements/UseSyncExternalStore.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shell/src/app/InspectableElements).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free