Skip to content

Conversation

@BPScott
Copy link
Member

@BPScott BPScott commented Aug 30, 2019

This PR is best viewed if you disable whitespace changes, as the hookification saves a level of indentation, which makes it look like i changed EVERYTHING

WHY are these changes introduced?

Starting down the path of removing withAppProvider usage into the new world of hooks.
Part of #1995

WHAT is this pull request doing?

Remove withAppProvider, and use hooks for the following components:

ActionMenu/RollupAction
Autocomplete
Card
EmptySearchResult
Form
SkeletonPage
TopBar

How to 🎩

  • ActionMeni/RollupAction: Confirm ... popover on with Page with action group example at small screen sizes renders and toggles on click
  • Autocomplete: Check interactions on any Autocomplete example
  • Card: Confirm secondary actions popover still works on Card
  • EmptySearchResult: Check <EmptySearchResult title="Title" description="Description" withIllustration /> renders in playground
  • Form: Check any form example
  • SkeletonPage: Check and skeleton page example
  • Topbar: check navigation visibility toggling works in Frame example at small screen sizes

@BPScott BPScott force-pushed the some-easy-hookifys branch from 3322a50 to a6442c2 Compare August 30, 2019 18:56
@BPScott BPScott mentioned this pull request Aug 30, 2019
@BPScott BPScott requested review from chloerice and dleroux August 30, 2019 19:12
@BPScott BPScott force-pushed the some-easy-hookifys branch 2 times, most recently from a3d727a to 5696e34 Compare August 30, 2019 19:37
return [state, toggle] as [typeof state, typeof toggle];
}

export function useForcableToggle(initialState: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a bit of a stretch, I would just do this manually in the file itself and I don't think it comes up often enough to warrant a custom hook. Idk, feels a bit weird, if others think it's fine I'm fine with it though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've saw cases where we want to force set a boolean toggle to false (e.g. when you click a modal's close button / leave focus in popovers.

I think this crops up often enough to make a general purpose thing.

Copy link
Contributor

@dleroux dleroux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@@ -0,0 +1,24 @@
import {useState, useCallback} from 'react';

export function useToggle(initialState: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why you did this, I just wonder it's worth it. It's simple but it requires knowledge about the hook and it's less declarative and just handling the toggle when needed. We aren't saving on much here imo.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same can be said for pretty much all of our custom hooks :)

IMO The value from these small utilities comes from encapsulation, that small amount of complexity saved adds up over the course of several components and its repeated presence means we'll become familiar with it over time for when we have a boolean toggle, which is pretty often.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for a really common usecase like a toggle variable it's fine. I agree that every hook adds to the cognitive load needed to understand the codebase, and we should avoid them

Remove withAppProvider, and use hooks for the following components:

ActionMenu/RollupAction
Autocomplete
Card
EmptySearchResult
Form
SkeletonPage
TopBar
@BPScott BPScott merged commit 066d30b into master Sep 3, 2019
@BPScott BPScott deleted the some-easy-hookifys branch September 3, 2019 19:40
chloerice pushed a commit that referenced this pull request Sep 6, 2019
* Convert a few simple components to use hooks

Remove withAppProvider, and use hooks for the following components:

ActionMenu/RollupAction
Autocomplete
Card
EmptySearchResult
Form
SkeletonPage
TopBar

* PR Feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants