Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hooks to events #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add hooks to events #6

wants to merge 3 commits into from

Conversation

mathdroid
Copy link
Collaborator

@mathdroid mathdroid commented Oct 26, 2018

  • Add hook to online event
  • Add hook to offline event
  • Add hook to both online and offline event
  • Add documentation
  • Add typing

@mathdroid mathdroid requested a review from hanford October 26, 2018 10:14
@mathdroid mathdroid mentioned this pull request Oct 26, 2018
onStatusChange = noop,
onOnline = noop,
onOffline = noop
}) {
Copy link

Choose a reason for hiding this comment

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

Suggested change
}) {
} = {}) {

This change would make the param optional

@hanford
Copy link
Member

hanford commented Oct 26, 2018

Not sure bringing a UI library in is a good idea, I would say these hooks should remain as small as possible to allow people consuming them to decide how they want to.

ie, if I'm not using evergreen, or don't like the look of these popups .. I can't really use this hook

Copy link
Member

@hanford hanford left a comment

Choose a reason for hiding this comment

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

alternatively you could create a hook and open source it under your own name with this functionality.

I would say bringing in evergreen ui might be out of scope for these hooks

@hanford
Copy link
Member

hanford commented Oct 26, 2018

thoughts @jamiebuilds @fouad ?

@mathdroid
Copy link
Collaborator Author

mathdroid commented Oct 26, 2018 via email

@jamiebuilds
Copy link
Member

Yeah, no need for UI, it's only going to make things more confusing

@jamesplease
Copy link
Member

Definitely no UI 😛

package.json Outdated
@@ -28,6 +28,7 @@
"devDependencies": {
"ava": "^0.25.0",
"browser-env": "^3.2.5",
"evergreen-ui": "^4.2.0",
Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit overkill to pull in a UI library


function MyComponent() {
let onlineStatus = useOnlineStatus();
let onlineStatus = useOnlineStatus({
onStatusChange: online =>
Copy link
Member

Choose a reason for hiding this comment

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

I feel like this should be implemented as something like <OnlineToaster status={onlineStatus} /> that triggers a toast on prop change rather than introducing a new concept to Hooks

Copy link
Member

Choose a reason for hiding this comment

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

This isn't really a new concept for hooks useImperativeMethods is basically this.

I think it's fine, but I would assume most of the time you'd use it for setX calls

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@fouad I can see the point you are making here. I added those hooks because I sometimes need to call some function whenever the online status changes. What do you people think? Should this be implemented here or not? 🙏

@mathdroid
Copy link
Collaborator Author

Just re-read the messages. I think @hanford mistook me for adding a UI lib for the main bundle. I didn't, and just used the toaster from evergreen-ui in the example (yarn example). I agree if the example toaster component should be changed though. @fouad @jamiebuilds

@mathdroid
Copy link
Collaborator Author

Not sure bringing a UI library in is a good idea, I would say these hooks should remain as small as possible to allow people consuming them to decide how they want to.

ie, if I'm not using evergreen, or don't like the look of these popups .. I can't really use this hook

This is giving the users more flexibility so they can pass their own hooks to the offline and online events. The evergreen toasters are just an example

@mathdroid
Copy link
Collaborator Author

I've removed the ui dependency and opt for a console.log example. Would the ability to add custom callbacks to online and offline events be a good feature though? @hanford @fouad @jamiebuilds @jamesplease

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.

6 participants