1. /**
    
  2.  * Copyright (c) Meta Platforms, Inc. and affiliates.
    
  3.  *
    
  4.  * This source code is licensed under the MIT license found in the
    
  5.  * LICENSE file in the root directory of this source tree.
    
  6.  *
    
  7.  * @flow
    
  8.  */
    
  9. 
    
  10. import * as React from 'react';
    
  11. import {Fragment, useDebugValue, useState} from 'react';
    
  12. 
    
  13. const div = document.createElement('div');
    
  14. const exampleFunction = () => {};
    
  15. const typedArray = new Uint8Array(3);
    
  16. typedArray[0] = 1;
    
  17. typedArray[1] = 2;
    
  18. typedArray[2] = 3;
    
  19. 
    
  20. const arrayOfArrays = [
    
  21.   [
    
  22.     ['a', 'b', 'c'],
    
  23.     ['d', 'e', 'f'],
    
  24.     ['h', 'i', 'j'],
    
  25.   ],
    
  26.   [
    
  27.     ['k', 'l', 'm'],
    
  28.     ['n', 'o', 'p'],
    
  29.     ['q', 'r', 's'],
    
  30.   ],
    
  31.   [['t', 'u', 'v'], ['w', 'x', 'y'], ['z']],
    
  32.   [],
    
  33. ];
    
  34. 
    
  35. const objectOfObjects = {
    
  36.   foo: {
    
  37.     a: 1,
    
  38.     b: 2,
    
  39.     c: 3,
    
  40.   },
    
  41.   bar: {
    
  42.     e: 4,
    
  43.     f: 5,
    
  44.     g: 6,
    
  45.   },
    
  46.   baz: {
    
  47.     h: 7,
    
  48.     i: 8,
    
  49.     j: 9,
    
  50.   },
    
  51.   qux: {},
    
  52. };
    
  53. 
    
  54. function useOuterFoo() {
    
  55.   useDebugValue({
    
  56.     debugA: {
    
  57.       debugB: {
    
  58.         debugC: 'abc',
    
  59.       },
    
  60.     },
    
  61.   });
    
  62.   useState({
    
  63.     valueA: {
    
  64.       valueB: {
    
  65.         valueC: 'abc',
    
  66.       },
    
  67.     },
    
  68.   });
    
  69.   return useInnerFoo();
    
  70. }
    
  71. 
    
  72. function useInnerFoo() {
    
  73.   const [value] = useState([[['a', 'b', 'c']]]);
    
  74.   return value;
    
  75. }
    
  76. 
    
  77. function useOuterBar() {
    
  78.   useDebugValue({
    
  79.     debugA: {
    
  80.       debugB: {
    
  81.         debugC: 'abc',
    
  82.       },
    
  83.     },
    
  84.   });
    
  85.   return useInnerBar();
    
  86. }
    
  87. 
    
  88. function useInnerBar() {
    
  89.   useDebugValue({
    
  90.     debugA: {
    
  91.       debugB: {
    
  92.         debugC: 'abc',
    
  93.       },
    
  94.     },
    
  95.   });
    
  96.   const [count] = useState(123);
    
  97.   return count;
    
  98. }
    
  99. 
    
  100. function useOuterBaz() {
    
  101.   return useInnerBaz();
    
  102. }
    
  103. 
    
  104. function useInnerBaz() {
    
  105.   const [count] = useState(123);
    
  106.   return count;
    
  107. }
    
  108. 
    
  109. export default function Hydration(): React.Node {
    
  110.   return (
    
  111.     <Fragment>
    
  112.       <h1>Hydration</h1>
    
  113.       <DehydratableProps
    
  114.         html_element={div}
    
  115.         fn={exampleFunction}
    
  116.         symbol={Symbol('symbol')}
    
  117.         react_element={<span />}
    
  118.         array_buffer={typedArray.buffer}
    
  119.         typed_array={typedArray}
    
  120.         date={new Date()}
    
  121.         array={arrayOfArrays}
    
  122.         object={objectOfObjects}
    
  123.       />
    
  124.       <DeepHooks />
    
  125.     </Fragment>
    
  126.   );
    
  127. }
    
  128. 
    
  129. function DehydratableProps({array, object}: any) {
    
  130.   return (
    
  131.     <ul>
    
  132.       <li>array: {JSON.stringify(array, null, 2)}</li>
    
  133.       <li>object: {JSON.stringify(object, null, 2)}</li>
    
  134.     </ul>
    
  135.   );
    
  136. }
    
  137. 
    
  138. function DeepHooks(props: any) {
    
  139.   const foo = useOuterFoo();
    
  140.   const bar = useOuterBar();
    
  141.   const baz = useOuterBaz();
    
  142.   return (
    
  143.     <ul>
    
  144.       <li>foo: {foo}</li>
    
  145.       <li>bar: {bar}</li>
    
  146.       <li>baz: {baz}</li>
    
  147.     </ul>
    
  148.   );
    
  149. }