From 0036b375028aecc00dc2efe1092dd2c80b0b5507 Mon Sep 17 00:00:00 2001 From: TinoM Date: Mon, 11 Mar 2024 21:46:59 +0200 Subject: [PATCH 1/2] Changed the documentation of the subscribe argument to a more accurate one. --- src/content/reference/react/useSyncExternalStore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/reference/react/useSyncExternalStore.md b/src/content/reference/react/useSyncExternalStore.md index ebaf0987b60..a87f9894c16 100644 --- a/src/content/reference/react/useSyncExternalStore.md +++ b/src/content/reference/react/useSyncExternalStore.md @@ -41,7 +41,7 @@ It returns the snapshot of the data in the store. You need to pass two functions #### Parameters {/*parameters*/} -* `subscribe`: A function that takes a single `callback` argument and subscribes it to the store. When the store changes, it should invoke the provided `callback`. This will cause the component to re-render. The `subscribe` function should return a function that cleans up the subscription. +* `subscribe`: A function that takes a single `callback` argument and subscribes it to the store. When the store changes, it should invoke the provided `callback`. This alerts React to potential changes in the store, but it will only cause the component to re-render if the snapshot, evaluated subsequently, has also changed. The `subscribe` function should return a function that removes the subscription when it's no longer needed. This helps prevent unnecessary re-renders and optimizes performance. * `getSnapshot`: A function that returns a snapshot of the data in the store that's needed by the component. While the store has not changed, repeated calls to `getSnapshot` must return the same value. If the store changes and the returned value is different (as compared by [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)), React re-renders the component. From abdff8cb8f373d19428811c4d049b03d63358676 Mon Sep 17 00:00:00 2001 From: Sophie Alpert Date: Sat, 7 Sep 2024 18:22:36 -0700 Subject: [PATCH 2/2] Update useSyncExternalStore.md --- src/content/reference/react/useSyncExternalStore.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/content/reference/react/useSyncExternalStore.md b/src/content/reference/react/useSyncExternalStore.md index a87f9894c16..53b441cd599 100644 --- a/src/content/reference/react/useSyncExternalStore.md +++ b/src/content/reference/react/useSyncExternalStore.md @@ -41,7 +41,7 @@ It returns the snapshot of the data in the store. You need to pass two functions #### Parameters {/*parameters*/} -* `subscribe`: A function that takes a single `callback` argument and subscribes it to the store. When the store changes, it should invoke the provided `callback`. This alerts React to potential changes in the store, but it will only cause the component to re-render if the snapshot, evaluated subsequently, has also changed. The `subscribe` function should return a function that removes the subscription when it's no longer needed. This helps prevent unnecessary re-renders and optimizes performance. +* `subscribe`: A function that takes a single `callback` argument and subscribes it to the store. When the store changes, it should invoke the provided `callback`, which will cause React to re-call `getSnapshot` and (if needed) re-render the component. The `subscribe` function should return a function that cleans up the subscription. * `getSnapshot`: A function that returns a snapshot of the data in the store that's needed by the component. While the store has not changed, repeated calls to `getSnapshot` must return the same value. If the store changes and the returned value is different (as compared by [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is)), React re-renders the component.