@@ -12,9 +12,19 @@ export function bind(node) {
12
12
} ;
13
13
}
14
14
15
+ /**
16
+ * History component that captures browser "history go back" actions and notifies the server.
17
+ *
18
+ * @param {Object } props - The properties object.
19
+ * @param {Function } props.onHistoryChangeCallback - Callback function to notify the server about history changes.
20
+ * @returns {null } This component does not render any visible output.
21
+ * @description
22
+ * This component uses the `popstate` event to detect when the user navigates back in the browser history.
23
+ * It then calls the `onHistoryChangeCallback` with the current pathname and search parameters.
24
+ * Note: Browsers do not allow detection of "history go forward" actions.
25
+ * @see https://github.com/reactive-python/reactpy/pull/1224
26
+ */
15
27
export function History ( { onHistoryChangeCallback } ) {
16
- // Capture browser "history go back" action and tell the server about it
17
- // Note: Browsers do not allow us to detect "history go forward" actions.
18
28
React . useEffect ( ( ) => {
19
29
// Register a listener for the "popstate" event and send data back to the server using the `onHistoryChange` callback.
20
30
const listener = ( ) => {
@@ -32,8 +42,10 @@ export function History({ onHistoryChangeCallback }) {
32
42
} ) ;
33
43
34
44
// Tell the server about the URL during the initial page load
35
- // FIXME: This currently runs every time any component is mounted due to a ReactPy core rendering bug.
45
+ // FIXME: This code is commented out since it currently runs every time any component
46
+ // is mounted due to a ReactPy core rendering bug.
36
47
// https://github.com/reactive-python/reactpy/pull/1224
48
+
37
49
// React.useEffect(() => {
38
50
// onHistoryChange({
39
51
// pathname: window.location.pathname,
@@ -44,10 +56,20 @@ export function History({ onHistoryChangeCallback }) {
44
56
return null ;
45
57
}
46
58
47
- // FIXME: The Link component is unused due to a ReactPy core rendering bug
48
- // which causes duplicate rendering (and thus duplicate event listeners).
49
- // https://github.com/reactive-python/reactpy/pull/1224
59
+
60
+ /**
61
+ * Link component that captures clicks on anchor links and notifies the server.
62
+ *
63
+ * @param {Object } props - The properties object.
64
+ * @param {Function } props.onClickCallback - Callback function to notify the server about link clicks.
65
+ * @param {string } props.linkClass - The class name of the anchor link.
66
+ * @returns {null } This component does not render any visible output.
67
+ */
50
68
export function Link ( { onClickCallback, linkClass } ) {
69
+ // FIXME: This component is currently unused due to a ReactPy core rendering bug
70
+ // which causes duplicate rendering (and thus duplicate event listeners).
71
+ // https://github.com/reactive-python/reactpy/pull/1224
72
+
51
73
// This component is not the actual anchor link.
52
74
// It is an event listener for the link component created by ReactPy.
53
75
React . useEffect ( ( ) => {
@@ -79,6 +101,15 @@ export function Link({ onClickCallback, linkClass }) {
79
101
return null ;
80
102
}
81
103
104
+ /**
105
+ * Client-side portion of the navigate component, that allows the server to command the client to change URLs.
106
+ *
107
+ * @param {Object } props - The properties object.
108
+ * @param {Function } props.onNavigateCallback - Callback function that transmits data to the server.
109
+ * @param {string } props.to - The target URL to navigate to.
110
+ * @param {boolean } props.replace - If true, replaces the current history entry instead of adding a new one.
111
+ * @returns {null } This component does not render anything.
112
+ */
82
113
export function Navigate ( { onNavigateCallback, to, replace } ) {
83
114
React . useEffect ( ( ) => {
84
115
if ( replace ) {
0 commit comments