File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed
Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -1121,9 +1121,30 @@ defmodule Phoenix.LiveView do
11211121 @ doc """
11221122 Accesses the connect params sent by the client for use on connected mount.
11231123
1124- Connect params are only sent when the client connects to the server and
1125- only remain available during mount. `nil` is returned when called in a
1126- disconnected state and a `RuntimeError` is raised if called after mount.
1124+ Connect params are sent from the client on every connection and reconnection.
1125+ The parameters in the client can be computed dynamically, allowing you to pass
1126+ client state to the server. For example, you could use it to compute and pass
1127+ the user time zone from a JavaScript client:
1128+
1129+ ```javascript
1130+ let liveSocket = new LiveSocket("/live", Socket, {
1131+ longPollFallbackMs: 2500,
1132+ params: (_liveViewName) => {
1133+ return {
1134+ _csrf_token: csrfToken,
1135+ time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone
1136+ }
1137+ }
1138+ })
1139+ ```
1140+
1141+ By computing the parameters with a function, reconnections will reevalute
1142+ the code, allowing you to fetch the latest data.
1143+
1144+ On the LiveView, you will use `get_connect_params/1` to read the data,
1145+ which only remains available during mount. `nil` is returned when called
1146+ in a disconnected state and a `RuntimeError` is raised if called after
1147+ mount.
11271148
11281149 ## Reserved params
11291150
You can’t perform that action at this time.
0 commit comments