Home / Function/ ProfilingImportExportButtons() — react Function Reference

ProfilingImportExportButtons() — react Function Reference

Architecture documentation for the ProfilingImportExportButtons() function in ProfilingImportExportButtons.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  be9c6f11_1325_f12c_25cc_7e13b55ab93e["ProfilingImportExportButtons()"]
  b191034a_a94e_84c8_d9bb_fcdcfa226cc1["ProfilingImportExportButtons.js"]
  be9c6f11_1325_f12c_25cc_7e13b55ab93e -->|defined in| b191034a_a94e_84c8_d9bb_fcdcfa226cc1
  03e3d573_f6a1_61a4_1749_cb4e0f3e2569["downloadFile()"]
  be9c6f11_1325_f12c_25cc_7e13b55ab93e -->|calls| 03e3d573_f6a1_61a4_1749_cb4e0f3e2569
  style be9c6f11_1325_f12c_25cc_7e13b55ab93e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-shared/src/devtools/views/Profiler/ProfilingImportExportButtons.js lines 30–155

export default function ProfilingImportExportButtons(): React.Node {
  const {isProfiling, profilingData, rootID} = useContext(ProfilerContext);
  const {setFile} = useContext(TimelineContext);
  const store = useContext(StoreContext);
  const {profilerStore} = store;

  const inputRef = useRef<HTMLInputElement | null>(null);
  const downloadRef = useRef<HTMLAnchorElement | null>(null);

  const {dispatch: modalDialogDispatch} = useContext(ModalDialogContext);

  const doesHaveInMemoryData = profilerStore.didRecordCommits;

  const downloadData = useCallback(() => {
    if (rootID === null) {
      return;
    }

    const anchorElement = downloadRef.current;

    if (profilingData !== null && anchorElement !== null) {
      const profilingDataExport = prepareProfilingDataExport(profilingData);
      const date = new Date();
      const dateString = date
        .toLocaleDateString(undefined, {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
        })
        .replace(/\//g, '-');
      const timeString = date
        .toLocaleTimeString(undefined, {
          hour12: false,
        })
        .replace(/:/g, '-');
      downloadFile(
        anchorElement,
        `profiling-data.${dateString}.${timeString}.json`,
        JSON.stringify(profilingDataExport, null, 2),
      );
    }
  }, [rootID, profilingData]);

  const clickInputElement = useCallback(() => {
    if (inputRef.current !== null) {
      inputRef.current.click();
    }
  }, []);

  // TODO (profiling) We should probably use a transition for this and suspend while loading the file.
  // Local files load so fast it's probably not very noticeable though.
  const handleChange = () => {
    const input = inputRef.current;
    if (input !== null && input.files.length > 0) {
      const file = input.files[0];

      // TODO (profiling) Handle fileReader errors.
      const fileReader = new FileReader();
      fileReader.addEventListener('load', () => {
        const raw = ((fileReader.result: any): string);
        const json = JSON.parse(raw);

        if (!isArray(json) && hasOwnProperty.call(json, 'version')) {
          // This looks like React profiling data.
          // But first, clear any User Timing marks; we should only have one type open at a time.
          setFile(null);

          try {
            const profilingDataExport = ((json: any): ProfilingDataExport);
            profilerStore.profilingData =
              prepareProfilingDataFrontendFromExport(profilingDataExport);
          } catch (error) {
            modalDialogDispatch({
              id: 'ProfilingImportExportButtons',
              type: 'SHOW',
              title: 'Import failed',
              content: (
                <Fragment>
                  <div>The profiling data you selected cannot be imported.</div>
                  {error !== null && (
                    <div className={styles.ErrorMessage}>{error.message}</div>

Domain

Subdomains

Frequently Asked Questions

What does ProfilingImportExportButtons() do?
ProfilingImportExportButtons() is a function in the react codebase, defined in packages/react-devtools-shared/src/devtools/views/Profiler/ProfilingImportExportButtons.js.
Where is ProfilingImportExportButtons() defined?
ProfilingImportExportButtons() is defined in packages/react-devtools-shared/src/devtools/views/Profiler/ProfilingImportExportButtons.js at line 30.
What does ProfilingImportExportButtons() call?
ProfilingImportExportButtons() calls 1 function(s): downloadFile.

Analyze Your Own Codebase

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

Try Supermodel Free