-
Notifications
You must be signed in to change notification settings - Fork 31
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
test: update styleguide to isolate by state #1960
Conversation
wusteven815
commented
Apr 24, 2024
•
edited
Loading
edited
- Refactor styleguide page to filter components by if it's rendered, instead of by CSS variables
- Refactor styleguide test to have sections be soft steps instead of its own step
- Refactor buttons section to be a function component
- Refactor styleguide test to run in parallel instead of serial
const hasMultipleThemes = themes.length > 1; | ||
|
||
function isHash(label: string, processLabel = false): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing this around via props, I would consider encapsulating the hash matching functionality in a custom hook. Something like:
function useIsHash() {
const [hash, setHash] = useState(window.location.hash);
useEffect(() => {
const hashChangeHandler = () => setHash(window.location.hash);
window.addEventListener('hashchange', hashChangeHandler);
return () => window.removeEventListener('hashchange', hashChangeHandler);
}, []);
const isHash = useCallback(
(label: string, processLabel = false): boolean => {
const newLabel = processLabel
? label.toLocaleLowerCase().replaceAll(' ', '-')
: label;
return hash === `#${newLabel}` || hash === '';
},
[hash]
);
return isHash;
}
Then you can just use it in any component like:
const isHash = useIsHash();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there something that can be done so that it doesn't have to be littered all over the place?
28a9891
to
c9a7e0b
Compare
307f746
to
33c0fe3
Compare
Closing in favor of ticket inspired by this one: #2000 |