Skip to content

Add hooks to events - #6

Open
mathdroid wants to merge 3 commits into
rehooks:masterfrom
mathdroid:master
Open

mathdroid wants to merge 3 commits into
rehooks:masterfrom
mathdroid:master

Conversation

@mathdroid

@mathdroid mathdroid commented Oct 26, 2018

Copy link
Copy Markdown
Collaborator
  • 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
Comment thread index.js
onStatusChange = noop,
onOnline = noop,
onOffline = noop
}) {

Copy link
Copy Markdown

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

hanford commented Oct 26, 2018

Copy link
Copy Markdown
Member

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

@hanford hanford left a comment

Copy link
Copy Markdown
Member

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

hanford commented Oct 26, 2018

Copy link
Copy Markdown
Member

thoughts @jamiebuilds @fouad ?

@mathdroid

mathdroid commented Oct 26, 2018 via email

Copy link
Copy Markdown
Collaborator Author

@jamiebuilds

Copy link
Copy Markdown
Member

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

@jamesplease

Copy link
Copy Markdown
Member

Definitely no UI 😛

Comment thread package.json Outdated
"devDependencies": {
"ava": "^0.25.0",
"browser-env": "^3.2.5",
"evergreen-ui": "^4.2.0",

Copy link
Copy Markdown
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

Comment thread README.md
function MyComponent() {
let onlineStatus = useOnlineStatus();
let onlineStatus = useOnlineStatus({
onStatusChange: online =>

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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