Skip to content

Commit 093ee5b

Browse files
Include use_helpers in all components (#1978)
* add: use_helper to base * add: changelog entry * add: pr suggestion * Update docs/guide/helpers.md Co-authored-by: Joel Hawksley <[email protected]> * Update docs/CHANGELOG.md Co-authored-by: Joel Hawksley <[email protected]> * Update test/sandbox/app/components/use_helpers_component.rb Co-authored-by: Joel Hawksley <[email protected]> * Update docs/CHANGELOG.md Co-authored-by: Joel Hawksley <[email protected]> --------- Co-authored-by: Joel Hawksley <[email protected]>
1 parent 459b4d8 commit 093ee5b

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ nav_order: 5
1010

1111
## main
1212

13+
* Include ViewComponent::UseHelpers by default.
14+
15+
*Reegan Viljoen*
16+
1317
* Bump `puma` in Gemfile.lock.
1418

1519
*Cameron Dutro*

docs/guide/helpers.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,10 @@ end
5555

5656
By default, ViewComponents don't have access to helper methods defined externally. The `use_helpers` method allows external helpers to be called from the component.
5757

58-
To use the `use_helpers` method, include `ViewComponent::UseHelpers`.
59-
`UseHelpers` defines the helper on the component and is similar in use to using `delegate` on helpers.
58+
`use_helpers` defines the helper on the component, similar to `delegate`:
6059

6160
```ruby
6261
class UseHelpersComponent < ViewComponent::Base
63-
include ViewComponent::UseHelpers
6462
use_helpers :icon
6563

6664
erb_template <<-ERB

lib/view_component/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ def config
2828
end
2929

3030
include ViewComponent::InlineTemplate
31+
include ViewComponent::UseHelpers
3132
include ViewComponent::Slotable
3233
include ViewComponent::Translatable
3334
include ViewComponent::WithContentHelper
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# frozen_string_literal: true
22

33
class UseHelpersComponent < ViewComponent::Base
4-
include ViewComponent::UseHelpers
5-
64
use_helpers :message
75
end

0 commit comments

Comments
 (0)