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

[@mantine/hooks] Fixing use-hash extra rerendering issue #3097

Merged
merged 4 commits into from Dec 4, 2022

Conversation

hunterwilhelm
Copy link
Contributor

Two bugs fixed:

  • If you setHash to something that doesn't start with "#" it would be reflect that temporarily in hash
  • setHashValue was being called multiple times (one in the listener and the set hash) resulting in the multiple renders

Result:

  • setHash only rerenders the page once.
  • hash consistently starts with '#'

Two bugs fixed:
* If you `setHash` to something that doesn't start with "#" it would be reflect that temporarily in `hash`
* `setHashValue` was being called multiple times (one in the listener and the set hash) resulting in the multiple renders

Result:
* `setHash` only rerenders the page once.
import { useWindowEvent } from '../use-window-event/use-window-event';

export function useHash() {
const [hash, setHashValue] = useState<string>('');
const [hash, setHashValue] = useState<string>(() => window.location.hash);
Copy link
Member

Choose a reason for hiding this comment

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

This will fail during ssr, window object does not exist.

@rtivital
Copy link
Member

rtivital commented Dec 2, 2022

Please fix failed tests

window is not defined in ssr
@rtivital
Copy link
Member

rtivital commented Dec 2, 2022

Please fix failed tests, before pushing run npm test.

@hunterwilhelm
Copy link
Contributor Author

Thanks! Sorry about that, I'm a little new to this.

@rtivital rtivital merged commit b2310e1 into mantinedev:master Dec 4, 2022
@rtivital
Copy link
Member

rtivital commented Dec 4, 2022

Thanks!

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.

None yet

2 participants