Skip to content

Conversation

@jcamposmk
Copy link
Contributor

@jcamposmk jcamposmk commented Jun 17, 2021

Fix console test errors

Add useTimeout hook in form-helpers and clean errors in console

useTimeout usage mode

  • import useTimeout from /hooks/useTimeout
  • create a constant inside the component: const createTimeout = useTimeout();
  • To create a timeout, use createTimeout(callback, delay)

escenario:

  • Run yarn test on console
  • All tests pass successfully

Results:

  • Local
    image

  • Jenkins
    image

// clear the timeout.
useEffect(() => {
return () => timerIds.map((timerId) => clearTimeout(timerId));
}, [timerIds]);
Copy link
Contributor

@andresmoschini andresmoschini Jun 18, 2021

Choose a reason for hiding this comment

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

Is using timerIds as a dependency fine? will it not clear existing timeouts each time you add a new one?

Copy link
Contributor

Choose a reason for hiding this comment

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

But the test shows me that it is working fine, what I am missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you're right. It causes me doubt, I will investigate


// clear the timeout.
useEffect(() => {
return () => timerIds.map((timerId) => clearTimeout(timerId));
Copy link
Contributor

Choose a reason for hiding this comment

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

I know that it is very opinionable, also, that this way is very idiomatic for some JS people.

I am not asking for a change, only starting a conversation.

In my opinion, it is better to keep functions like map to map, it means to convert each item of a list into a different item in a new list without side effects.

clearTimeout is a effect, for that reason, I think that for will be clear here.

I know that it is not for JS ecosystem, but I think that these Eric Lippert's reflections applyies here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I hadn't seen it that way, but it makes sense

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess it gives more expression to the code

Comment on lines 44 to 47
useEffect(() => {
createTimeout(callback, delay);
createTimeout(callback2, delay2);
}, []);
Copy link
Contributor

Choose a reason for hiding this comment

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

useEffect is not necessary here right?

Suggested change
useEffect(() => {
createTimeout(callback, delay);
createTimeout(callback2, delay2);
}, []);
createTimeout(callback, delay);
createTimeout(callback2, delay2);

I mean, useTimeout already has the useEffect inside, and in our real scenario, we are not using useTimeout inside useEffect.

Copy link
Contributor Author

@jcamposmk jcamposmk Jun 18, 2021

Choose a reason for hiding this comment

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

I use the useEffect in renderHook's to be able to execute the createTimemout function. it is the easiest way to use it. in the scenario we have right now (form-helpers) it is not used in the useEffect, but it could be used, since it is a function
If I don't put it, it will show me that the setTimeout has been called too many times.

image

what I can do is simulate that these calls to createTimeout are made within a function, and trigger the function by clicking on a fake button.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed!

@cbernat
Copy link
Contributor

cbernat commented Jun 18, 2021

Nice! 👍

@jcamposmk jcamposmk merged commit fb1db76 into FromDoppler:master Jun 22, 2021
@andresmoschini
Copy link
Contributor

🎉 This PR is included in version 1.179.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants