Skip to content

Commit

Permalink
docs: lazy -> optional
Browse files Browse the repository at this point in the history
  • Loading branch information
skryukov committed Oct 14, 2024
1 parent dfef20d commit b922645
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions docs/guide/partial-reloads.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,21 @@ end

When Inertia performs a request, it will determine which data is required and only then will it evaluate the closure. This can significantly increase the performance of pages that contain a lot of optional data.

Additionally, Inertia provides an `InertiaRails.lazy` method to specify that a prop should never be included unless explicitly requested using the `only` option:
Additionally, Inertia provides an `InertiaRails.optional` method to specify that a prop should never be included unless explicitly requested using the `only` option:

```ruby
class UsersController < ApplicationController
def index
render inertia: 'Users/Index', props: {
users: InertiaRails.lazy(-> { User.all }),
users: InertiaRails.optional(-> { User.all }),
}
end
end
```

> [!NOTE]
> Prior to Inertia.js v2, the method `InertiaRails.lazy` was used. It is now deprecated and has been replaced by `InertiaRails.optional`. Please update your code accordingly to ensure compatibility with the latest version.
On the inverse, you can use the `InertiaRails.always` method to specify that a prop should always be included, even if it has not been explicitly required in a partial reload.

```ruby
Expand Down Expand Up @@ -207,7 +210,7 @@ class UsersController < ApplicationController
# NEVER included on standard visits
# OPTIONALLY included on partial reloads
# ONLY evaluated when needed
users: InertiaRails.lazy(-> { User.all }),
users: InertiaRails.optional(-> { User.all }),

# ALWAYS included on standard visits
# ALWAYS included on partial reloads
Expand Down

0 comments on commit b922645

Please sign in to comment.