<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                [TOC] ## useSyncExternalStore 1. 如果你需要去集成已有的非 React 代碼,`useSyncExternalStore` API 是很有用的。 2. 調用向使用瀏覽器的API ## 示例 sub.ts ``` import { useSyncExternalStore } from 'react'; import { counterStore } from '../lib/sub'; function Counter() { const count = useSyncExternalStore( counterStore.subscribe, counterStore.getSnapshot, counterStore.getServerSnapshot ); return ( <div> <p>計數: {count}</p> <button onClick={() => counterStore.setValue(count + 1)}> 增加 </button> </div> ); } export default Counter; ``` demo.txs ``` import { useSyncExternalStore } from 'react'; import { counterStore } from '../lib/sub'; function Counter() { const count = useSyncExternalStore( counterStore.subscribe, counterStore.getSnapshot, counterStore.getServerSnapshot ); return ( <div> <p>計數: {count}</p> <button onClick={() => counterStore.setValue(count + 1)}> 增加 </button> </div> ); } export default Counter; ``` 通常可以把useSyncExternalStore 封裝到 hook 中 如 ``` import { counterStore } from "@/lib/sub"; import { useSyncExternalStore } from "react"; export const useCount = () => { const count = useSyncExternalStore( counterStore.subscribe, counterStore.getSnapshot, counterStore.getServerSnapshot ); return count } ``` 調用 ``` // 子組件 function Counter() { const count = useCount() return ( <div> <p>計數: {count}</p> </div> ); } // 調用 export default function Demo(){ const count = useCount() return <div> <Counter /> <Counter /> <button onClick={() => counterStore.setValue(count + 1)}>button</button> </div> } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看