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 React, {useEffect, useState} from 'react';
    
  11. 
    
  12. export function Component() {
    
  13.   const countState = useState(0);
    
  14.   const count = countState[0];
    
  15.   const setCount = countState[1];
    
  16. 
    
  17.   const darkMode = useIsDarkMode();
    
  18.   const [isDarkMode] = darkMode;
    
  19. 
    
  20.   useEffect(() => {
    
  21.     // ...
    
  22.   }, []);
    
  23. 
    
  24.   const handleClick = () => setCount(count + 1);
    
  25. 
    
  26.   return (
    
  27.     <>
    
  28.       <div>Dark mode? {isDarkMode}</div>
    
  29.       <div>Count: {count}</div>
    
  30.       <button onClick={handleClick}>Update count</button>
    
  31.     </>
    
  32.   );
    
  33. }
    
  34. 
    
  35. function useIsDarkMode() {
    
  36.   const darkModeState = useState(false);
    
  37.   const [isDarkMode] = darkModeState;
    
  38. 
    
  39.   useEffect(function useEffectCreate() {
    
  40.     // Here is where we may listen to a "theme" event...
    
  41.   }, []);
    
  42. 
    
  43.   return [isDarkMode, () => {}];
    
  44. }